Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int B = 1e9 + 7;
- const int L = 1500;
- lli enc[26];
- char strA[L], strB[L];
- int main(){
- enc[0] = 1;
- for(int i = 1; i < 26; ++i){
- enc[i] = enc[i - 1] * B;
- }
- scanf(" %s %s", strA + 1, strB + 1);
- int lenA = strlen(strA + 1);
- int lenB = strlen(strB + 1);
- int len = min(lenA, lenB);
- for(int i = len; i >= 1; --i){
- lli hsh = 0;
- set<lli> stt;
- for(int j = 1; j <= i; ++j){
- hsh += enc[strA[j] - 'a'];
- }
- stt.insert(hsh);
- for(int j = i + 1; j <= lenA; ++j){
- hsh -= enc[strA[j - i] - 'a'];
- hsh += enc[strA[j] - 'a'];
- stt.insert(hsh);
- }
- hsh = 0;
- for(int j = 1; j <= i; ++j){
- hsh += enc[strB[j] - 'a'];
- }
- if(stt.find(hsh) != stt.end()){
- cout << i;
- return 0;
- }
- for(int j = i + 1; j <= lenB; ++j){
- hsh -= enc[strB[j - i] - 'a'];
- hsh += enc[strB[j] - 'a'];
- if(stt.find(hsh) != stt.end()){
- cout << i;
- return 0;
- }
- }
- }
- cout << '0';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement