#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#define LL long long
#define pll pair<LL,LL>
#define plli pair<pll,int>
#define ff first
#define ss second
using namespace std;
char s1[1555],s2[1555];
LL MOD[2]={(LL)1e9+7,(LL)1e9+9};
LL mul[2][1555];
LL hash1[2][1555],hash2[2][1555];
vector<plli> res;
int main(){
int len1,len2,len;
scanf("%s %s",s1,s2);
len1=strlen(s1); len2=strlen(s2);
len=min(len1,len2);
mul[0][0]=mul[1][0]=1;
for(int t=0;t<2;t++)
for(int i=1;i<26;i++) mul[t][i]=(mul[t][i-1]*len)%MOD[t];
int ans=0;
for(int t=0;t<2;t++){
for(int i=0;i<len1;i++) hash1[t][i]=mul[t][s1[i]-'a'];
for(int i=0;i<len2;i++) hash2[t][i]=mul[t][s2[i]-'a'];
}
for(int i=0;i<len1;i++) res.push_back({{hash1[0][i],hash1[1][i]},1});
for(int i=0;i<len2;i++) res.push_back({{hash2[0][i],hash2[1][i]},2});
sort(res.begin(),res.end());
// printf("1\n");
// for(int i=0;i<res.size();i++) printf("%10lld %10lld %d\n",res[i].ff.ff,res[i].ff.ss,res[i].ss);
// printf("\n\n\n");
for(int i=1;i<res.size();i++){
if(res[i-1].ff==res[i].ff && res[i-1].ss+res[i].ss==3) ans=1;
}
for(int i=1;i<len;i++){
res.clear();
for(int t=0;t<2;t++){
for(int j=len1-1;j>=i-1;j--) hash1[t][j]=(hash1[t][j-1]+mul[t][s1[j]-'a'])%MOD[t];
for(int j=len2-1;j>=i-1;j--) hash2[t][j]=(hash2[t][j-1]+mul[t][s2[j]-'a'])%MOD[t];
}
for(int j=0;j<len1;j++) res.push_back({{hash1[0][j],hash1[1][j]},1});
for(int j=0;j<len2;j++) res.push_back({{hash2[0][j],hash2[1][j]},2});
sort(res.begin(),res.end());
// printf("%d\n",i+1);
// for(int i=0;i<res.size();i++) printf("%10lld %10lld %d\n",res[i].ff.ff,res[i].ff.ss,res[i].ss);
// printf("\n\n\n");
for(int j=1;j<res.size();j++){
if(res[j-1].ff==res[j].ff && res[j-1].ss+res[j].ss==3) ans=i+1;
}
}
printf("%d",ans);
return 0;
}
Compilation message
interval.cpp: In function 'int main()':
interval.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<res.size();i++){
~^~~~~~~~~~~
interval.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<res.size();j++){
~^~~~~~~~~~~
interval.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s %s",s1,s2);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
560 KB |
Output is correct |
2 |
Correct |
30 ms |
608 KB |
Output is correct |
3 |
Incorrect |
35 ms |
672 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
700 KB |
Output is correct |
2 |
Correct |
185 ms |
700 KB |
Output is correct |
3 |
Correct |
191 ms |
700 KB |
Output is correct |
4 |
Correct |
185 ms |
700 KB |
Output is correct |
5 |
Correct |
194 ms |
828 KB |
Output is correct |
6 |
Incorrect |
169 ms |
828 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
227 ms |
828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |