Created
October 19, 2016 07:13
-
-
Save Yazaten/ecee57825c9e87830f1fe82cfec2ac05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "bits/stdc++.h" | |
#include <array> | |
using namespace std; | |
#define rep(i,n) for(int i=0;i<(int)(n);i++) | |
int main(){ | |
int ans=0; | |
string s,t; | |
cin>>s>>t; | |
if(s.size()>t.size())swap(s,t); | |
for(int l=1;l<=s.size();l++){ //長さLのアナグラムについて考える | |
map<array<int,26>,bool> mp; | |
array<int,26> a,b; | |
rep(i,26)a[i]=b[i]=0; | |
rep(i,l)a[s[i]-'a']++; | |
mp[a]=true; | |
rep(i,s.size()-l){ //しゃくとり法っぽくやる | |
a[s[i]-'a']--; | |
a[s[i+l]-'a']++; | |
mp[a]=true; | |
} | |
rep(i,l)b[t[i]-'a']++; | |
if(mp.count(b))ans = max(ans,l); | |
rep(i,t.size()-l){ //しゃくとり法っぽくやる | |
b[t[i]-'a']--; | |
b[t[i+l]-'a']++; | |
if(mp.count(b))ans = max(ans,l); | |
} | |
} | |
cout<<ans<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment