#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
long long s,d[30],f,g,h,j,k,n,m,mod=1000000000000009,mar=1507;
int i,a,l;
string x,z;
unordered_set<long long> q[2002];
main(){
//ios::sync_with_stdio(0);
d[0]=1;
for(i=1;i<30;i++){
d[i]=(d[i-1]*mar)%mod;
}
char c;
while((c=getchar())!='\n') x+=c;
while((c=getchar())!='\n') z+=c;
//if(x.size()>z.size()) swap(x,z);
//cout<<"*"<<x<<" "<<z<<"*";
n=x.size();
for(i=0;i<x.size();i++) x[i]-='a';
for(i=0;i<z.size();i++) z[i]-='a';
for(i=0;i<n;i++){
h=0;
for(a=i;a<n;a++){
h+=d[x[a]];
if(h>mod) h-=mod;
q[a-i].insert(h);
}
}
m=z.size();
for(i=0;i<m;i++){
h=0;
//f=min(z.size(),i+x.size());
for(a=i;a<m;a++){
//if(a>i+x.size()) break;
h+=d[z[a]];
if(h>mod) h-=mod;
if(l<a-i+1 && q[a-i].find(h)!=q[a-i].end()) l=a-i+1;
}
}
cout<<l;
}
Compilation message
interval.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
interval.cpp: In function 'int main()':
interval.cpp:20:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<x.size();i++) x[i]-='a';
~^~~~~~~~~
interval.cpp:21:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<z.size();i++) z[i]-='a';
~^~~~~~~~~
interval.cpp:25:22: warning: array subscript has type 'char' [-Wchar-subscripts]
h+=d[x[a]];
^
interval.cpp:37:22: warning: array subscript has type 'char' [-Wchar-subscripts]
h+=d[z[a]];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
612 KB |
Output is correct |
4 |
Correct |
4 ms |
696 KB |
Output is correct |
5 |
Correct |
5 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
3852 KB |
Output is correct |
2 |
Correct |
58 ms |
4748 KB |
Output is correct |
3 |
Correct |
6 ms |
4748 KB |
Output is correct |
4 |
Correct |
5 ms |
4748 KB |
Output is correct |
5 |
Correct |
57 ms |
5696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
436 ms |
20624 KB |
Output is correct |
2 |
Correct |
425 ms |
21568 KB |
Output is correct |
3 |
Correct |
405 ms |
21568 KB |
Output is correct |
4 |
Correct |
369 ms |
21568 KB |
Output is correct |
5 |
Correct |
402 ms |
21568 KB |
Output is correct |
6 |
Correct |
550 ms |
21568 KB |
Output is correct |
7 |
Correct |
443 ms |
21568 KB |
Output is correct |
8 |
Correct |
386 ms |
21584 KB |
Output is correct |
9 |
Correct |
381 ms |
21584 KB |
Output is correct |
10 |
Correct |
393 ms |
21584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
21584 KB |
Output is correct |
2 |
Correct |
903 ms |
43084 KB |
Output is correct |
3 |
Correct |
804 ms |
43084 KB |
Output is correct |
4 |
Correct |
195 ms |
43084 KB |
Output is correct |
5 |
Execution timed out |
1074 ms |
46168 KB |
Time limit exceeded |