# include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 2;
string s;
int n;
long long ans, h[N], pw[N], pr = 53, mod = 1e9 + 7;
map < pair <long long, long long> , long long> mp;
long long get(int l, int r){
long long hs = h[r] - h[l - 1] + mod;
hs %= mod;
hs *= pw[N - r];
return hs % mod;
}
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] - 'a' + 1) * pw[i]) % mod) % 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 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
408 KB |
Output is correct |
5 |
Incorrect |
2 ms |
408 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
1276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
1408 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 |
13 ms |
2036 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |