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>
#define N 300005
#define K 30
using namespace std;
const int base = 31;
const int mod = 1e9 + 7;
const int base2 = 41;
const int mod2 = 1e9 + 21;
int cnt[N][K];
int val[N];
long long pre[N];
long long pw[N];
long long pre2[N];
long long pw2[N];
vector<int> palindromes[N];
void solve(){
string s;
cin >> s;
int n = s.size();
s = "." + s;
for(int i=1;i<=n;i++){
pre[i] = (pre[i-1] * base + (s[i] - 'a'))%mod;
pre2[i] = (pre2[i-1] * base2 + (s[i] - 'a'))%mod2;
}
long long ans = 0;
map<pair<int,int>,int> mp;
for(int i = n;i>=1;i--){
if(i == n || s[i+1] != s[i]){
val[i] = 1;
}
else val[i] = val[i+1] + 1;
palindromes[i].push_back(i + val[i] - 1);
cnt[val[i]][s[i] - 'a']++;
for(auto u:palindromes[i+1]){
if(u + 1 <= n && s[u+1] == s[i] && u + 1 > i + val[i] - 1){
palindromes[i].push_back(u+1);
}
}
assert(palindromes[i].size() <= 100);
/*
for(auto u:palindromes[i]){
ans = max(ans,1ll*(u-i + 1) * (++mp[{(pre[u] - pw[(u-i + 1)] * pre[i-1] % mod + mod)%mod,(pre2[u] - pw2[(u-i + 1)] * pre2[i-1] % mod2 + mod2)%mod2}]));
}*/
}
for(int i=n;i>=1;i--){
for(int c = 0;c<K;c++){
cnt[i][c] += cnt[i+1][c];
ans = max(ans,1ll*i*cnt[i][c]);
}
}
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
pw[0] = 1;
pw2[0] = 1;
for(int i = 1;i<N;i++){
pw[i] = pw[i-1] * base % mod;
pw2[i] = pw2[i-1] * base2 % mod2;
}
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | 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... |