#include<bits/stdc++.h>
using namespace std;
int A = 987654323;
int B = 1e9 + 9;
int C = 985201597;
int D = 660353359;
int pol1[26];
int pol2[26];
set<pair<int,int> > sa[1509];
main(){
pol1[0] = 1;
for(int i = 1; i < 26; i ++)
pol1[i] = (long long)pol1[i - 1] * (long long)A % B;
pol2[0] = 1;
for(int i = 1; i < 26; i ++)
pol2[i] = (long long)pol2[i - 1] * (long long)C % D;
int n, m;
string a, b;
cin >> a >> b;
n = a.size(), m = b.size();
for(int i = 0; i < n; i++){
int H1 = 0, H2 = 0;
for(int j = i; j < n; j++){
H1 += pol1[a[j] - 'a'];
H2 += pol2[a[j] - 'a'];
if(H1 >= B) H1 -= B;
if(H2 >= D) H2 -= D;
sa[j - i + 1].insert({H1,H2});
}
}
int ans = 0;
for(int i = 0; i < m; i++){
int H1 = 0, H2 = 0;
for(int j = i; j < m; j++){
H1 += pol1[b[j] - 'a'];
H2 += pol2[b[j] - 'a'];
if(H1 >= B) H1 -= B;
if(H2 >= D) H2 -= D;
if(sa[j - i + 1].find({H1,H2}) != sa[j - i + 1].end()){
ans = max(ans, j - i + 1);
}
}
}
cout << ans << endl;
}
Compilation message
interval.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
4 ms |
520 KB |
Output is correct |
4 |
Correct |
3 ms |
820 KB |
Output is correct |
5 |
Correct |
3 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
4352 KB |
Output is correct |
2 |
Correct |
65 ms |
5068 KB |
Output is correct |
3 |
Correct |
10 ms |
5068 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
111 ms |
5840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
856 ms |
22184 KB |
Output is correct |
2 |
Correct |
766 ms |
22960 KB |
Output is correct |
3 |
Correct |
756 ms |
22960 KB |
Output is correct |
4 |
Correct |
806 ms |
22960 KB |
Output is correct |
5 |
Correct |
827 ms |
23120 KB |
Output is correct |
6 |
Correct |
867 ms |
23120 KB |
Output is correct |
7 |
Correct |
947 ms |
23120 KB |
Output is correct |
8 |
Correct |
900 ms |
23120 KB |
Output is correct |
9 |
Correct |
796 ms |
23120 KB |
Output is correct |
10 |
Correct |
853 ms |
23120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
275 ms |
23120 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
46500 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |