Skip to content

Instantly share code, notes, and snippets.

@Yazaten
Created October 19, 2016 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yazaten/ecee57825c9e87830f1fe82cfec2ac05 to your computer and use it in GitHub Desktop.
Save Yazaten/ecee57825c9e87830f1fe82cfec2ac05 to your computer and use it in GitHub Desktop.
#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