#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 3000*100+7;
const long long MOD = 1000000007;
long long h1[N],h2[N];
long long p[N];
long long hashcode1(int l,int r){
return h1[r]-(h1[l-1]*p[r-l+1])%MOD;
}
long long hashcode2(int l,int r){
return h2[r]-(h2[l-1]*p[r-l+1])%MOD;
}
int main()
{
string s;
cin>>s;
int n = s.length();
p[0] = 1;
for(int i = 1;i<=n;i++) p[i] = (p[i-1]*239)%MOD;
string srev = s;
reverse(srev.begin(),srev.end());
for(int i = 1;i<=n;i++){
h1[i] = (h1[i-1]*239+s[i-1])%MOD;
h2[i] = (h2[i-1]*239+srev[i-1])%MOD;
}
map<long long,int> mp;
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = i;j<=n;j++){
int x = hashcode1(i,j);
int jj = n-i+1;
int ii = n-j+1;
int y = hashcode2(ii,jj);
if(x == y){
mp[x]++;
ans = max(ans,(j-i+1)*mp[x]);
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
576 KB |
Output is correct |
5 |
Correct |
2 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
2 ms |
576 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
3 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Incorrect |
3 ms |
720 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
2312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
13184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
29828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |