#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 2005;
int A = 37;
int B = 1e9 + 9;
int C = 31;
int D = 1e9 + 2;
string s , t;
int pw1[27] , pw2[27];
map<pair<int , int> , int> mp;
main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> s >> t;
int n = s.size() , m = t.size();
pw1[0] = pw2[0] = 1;
for(int i = 1; i < 26; ++i) pw1[i] = pw1[i - 1] * A*(i + 1) % B;
for(int i = 1; i< 26; ++i) pw2[i] = pw2[i - 1] * C*(i + 1) % D;
for(int i = 0; i < n; ++i){
int x= 0 , y =0;
for(int j = i; j < n; ++j){
x += pw1[s[j] - 'a'];
y += pw2[s[j] - 'a'];
if(x>=B)x-=B;
if(y>=D)y-=D;
// a[j - i + 1].emplace_back(x , y);
mp[{x , y}] = 1;
}
}
int ans = 0;
for(int i = 0; i < m; ++i){
int x= 0 , y =0;
for(int j = i; j < m; ++j){
x += pw1[t[j] - 'a'];
y += pw2[t[j] - 'a'];
if(x>=B)x-=B;
if(y>=D)y-=D;
if(mp[{x, y}])ans = max(ans , j - i + 1);
}
}
cout << ans;
}
Compilation message
interval.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
14 | main (){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
816 KB |
Output is correct |
5 |
Correct |
3 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
12500 KB |
Output is correct |
2 |
Correct |
57 ms |
10040 KB |
Output is correct |
3 |
Correct |
20 ms |
844 KB |
Output is correct |
4 |
Correct |
7 ms |
332 KB |
Output is correct |
5 |
Correct |
115 ms |
14276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
793 ms |
57660 KB |
Output is correct |
2 |
Correct |
885 ms |
59832 KB |
Output is correct |
3 |
Correct |
843 ms |
59256 KB |
Output is correct |
4 |
Correct |
801 ms |
57724 KB |
Output is correct |
5 |
Correct |
950 ms |
59720 KB |
Output is correct |
6 |
Correct |
802 ms |
58112 KB |
Output is correct |
7 |
Correct |
931 ms |
59716 KB |
Output is correct |
8 |
Correct |
906 ms |
59872 KB |
Output is correct |
9 |
Correct |
953 ms |
59744 KB |
Output is correct |
10 |
Correct |
859 ms |
59544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
311 ms |
19428 KB |
Output is correct |
2 |
Execution timed out |
1098 ms |
93136 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |