Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#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