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;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, l l>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for ( int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
const ll seed=31;
ll po[100005]={1}, ans;
int n, r[200005], rit, c, k, x, y, p;
string s, t="#";
map<int, ll> m;
void add(int X, ll V){
if (m.count(X)==0) m[X]=0;
m[X]+=V;
}
int main(){
fox1(l, 100001) po[l]=(po[l-1]*31)%MN;
cin >> s;
//s="";
//fox(l, 100000) s+='a';
fox(l, s.size()){
t+=s[l]; t+="#";
}
s=t;
//cout << s << endl;
n=s.size();
fox(l, n){
if (l>rit) r[l]=0;
else r[l]=r[2*p-l];
while(l-r[l]>0 && l+r[l]<n-1 && s[l-r[l]]==s[l+r[l]]) r[l]++;
if (l+r[l]>rit){
rit=l+r[l];
p=l;
}
//cout << r[l] << ' ';
}
//cout << endl;
rit=-1;
fox(l, n){
if (r[l]==0) continue;
if (l+r[l]>rit){
k=r[l]; p=l+k;
while(1){
//cout << k<< ' ' << p << endl;
while(k>=r[l] && r[p]<k*2) k/=2;
if (k<r[l]) break;
k*=2; p+=k;
}
c=(p-l+r[l])/2/r[l];
//continue;
x=0; k=0;
for(int l2=l-r[l]+1; l2<=l+r[l]-1; l2+=2){
x=(seed*x+(s[l2]-'a'+1))%MN; ++k;
}
y=x;
//cout << l << ' ' << r[l] << ' ' << c << endl;
fox1(l2, c){
add(y, 1LL*(c-l2+1)*l2*r[l]);
y=(y*po[k]+x)%MN;
//if (y<10)cout << y << ' ';
}
rit=p+1;
}
}
for(map<int, ll>::iterator i=m.begin(); i!=m.end(); ++i){
ans=max(ans, i->y);
}
cout << ans;
return 0;
}
Compilation message (stderr)
palindrome.cpp: In function 'int main()':
palindrome.cpp:18:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for ( int k=0; k<x; ++k)
^
palindrome.cpp:41:5: note: in expansion of macro 'fox'
fox(l, s.size()){
^
# | 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... |