This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 2;
string s;
int n;
long long ans, h[N], has[N], pw[N], p[N], pr = 997, mod = 1e9 + 7;
map < pair <int, 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;
}
int Get(int l, int r){
long long hs = (has[r] - has[l - 1] + mod) % mod;
hs = (hs * p[N - l]) % mod;
return hs;
}
bool ispal(int l, int r){
return get(l, r) == get(n - r + 1, n - l + 1) && Get(l, r) == Get(n - r + 1, n - l + 1);
}
int main(){
pw[0] = pr;
p[0] = pr;
for(int i = 1; i < N; i ++){
pw[i] = pw[i - 1] * pr;
p[i] = (p[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];
has[i] = (has[i - 1] + s[i] * p[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), 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |