# include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 2;
string s;
int n;
long long ans, h[N], pw[N], pr = 997, mod = 1e9 + 7;
map < pair <int, int> , int> mp;
int get(int l, int r){
long long hs = h[r] - h[l - 1];
hs *= pw[N - l];
return hs;
}
bool ispal(int l, int r){
return get(l, r) == get(n - r + 1, n - l + 1);
}
int main(){
pw[0] = pr;
for(int i = 1; i < N; i ++)
pw[i] = (pw[i - 1] * pr) % mod;
cin >> s;
n = s.size();
s = ' ' + s;
for(int i = 1; i <= n; i ++){
h[i] = (h[i - 1] + s[i] * pw[i]) % mod;
}
for(int i = 1; i <= n; i ++){
for(int j = i; j <= n; j ++){
if(ispal(i, j)){
mp[{j - i + 1, get(i, j)}] ++;
}
}
}
for(auto i : mp){
long long cur = i.first.first * i.second;
ans = max(ans, cur);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
234 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
1484 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
1776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |