Pagini recente » Rating Dan Buleriu Turcu (baloo) | Istoria paginii utilizator/costinteo | Monitorul de evaluare | Cod sursa (job #2174229) | Cod sursa (job #1503804)
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <queue>
#include <cstring>
#include <map>
#include <unordered_set>
using namespace std;
#define sq 300
#define maxn 100010
int pal[2000010];
char t[2000010], s[1000010];
int main()
{
freopen("pscpld.in","r",stdin);
freopen("pscpld.out","w",stdout);
ios_base::sync_with_stdio(false);
cin >> s;
int m = strlen(s);
t[0] = '0';
for (int i = 0; i < m; ++i)
{
t[2*i+1] = s[i];
t[2*i+2] = '0';
}
int n = strlen(t);
pal[0] = 0;
int bst = 0;
long long ans = 0;
for (int i = 1; i < n; ++i)
{
if (bst+pal[bst] < i || pal[bst-(i-bst)] >= bst+pal[bst] - i)
{
bst = i;
if(bst-(i-bst) >= 0)
pal[i] = pal[bst-(i-bst)];
while (i+pal[i] < n && t[i+pal[i]] == t[i-pal[i]])
++pal[i];
--pal[i];
}
else
{
pal[i] = pal[bst-(i-bst)];
}
if (t[i] == '0')
ans += (pal[i]+1)/2;
else ans += 1 + pal[i]/2;
}
cout << ans;
}