Pagini recente » Cod sursa (job #3355687) | Cod sursa (job #3317911) | Cod sursa (job #3302554) | Cod sursa (job #3317912) | Cod sursa (job #3305257)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin ("pscpld.in");
ofstream fout ("pscpld.out");
int mnch[2000002];
signed main()
{
string S, citit;
fin >> citit;
S = "&&";
for (auto x:citit){
S += x;
S += "&";
}
int best = 0;
for (int i=1;i<S.size();++i){
if (best+mnch[best]>=i){
mnch[i] = min(mnch[best-(i-best)],best+mnch[best]-i);
while (i+mnch[i]+1<S.size() and i-mnch[i]-1>=1 and S[i+mnch[i]+1]==S[i-mnch[i]-1]){
mnch[i]++;
}
if (i+mnch[i]>=best+mnch[best]){
best = i;
}
}else{
mnch[i] = 0;
while (i+mnch[i]+1<S.size() and i-mnch[i]-1>=1 and S[i+mnch[i]+1]==S[i-mnch[i]-1]){
mnch[i]++;
}
best = i;
}
}
int ans = 0;
for (int i=1;i<S.size();++i){
ans +=(mnch[i]+1)/2;
}
fout << ans;
return 0;
}