Pagini recente » Cod sursa (job #1350004) | Cod sursa (job #1507520) | Cod sursa (job #1786385) | Cod sursa (job #1441509) | Cod sursa (job #1227536)
#include<stdio.h>
#define fin "pscpld.in"
#define fout "pscpld.out"
#define Nmax 2100001
#define Max 1100001
#define FL
#define DBGx
int N, len[Nmax];
char v[Nmax];
long long ret;
int main()
{
int i, a, b, poz;
char buff[Max];
freopen(fin, "r", stdin);
#ifdef FL
freopen(fout, "w", stdout);
#endif
fgets(buff, Max, stdin);
N = 1; v[1] = ' ';
i = 0;
while (buff[i] != '\n' && buff[i] != EOF)
{
v[++N] = buff[i++];
v[++N] = ' ';
}
a = 1; b = 3;
len[2] = 1;
for (i = 3; i <= N; ++i)
{
#ifdef DBG
printf("%d: %d %d\n", i, a, b);
#endif
if (i <= b)
{
poz = b - i;
if (i + len[a + poz] >= b)
{
len[i] = b - i;
b = i + len[i];
a = i - len[i];
while (v[a - 1] == v[b + 1] && a>1)
{
++len[i];
++b;
--a;
}
}
else
len[i] = len[a + poz];
}
else
{
len[i] = 0;
a = i; b = i;
while (v[a - 1] == v[b + 1] && a>1)
{
++len[i];
++b;
--a;
}
}
#ifdef DBG
for (int j = 1; j <= N; ++j)
printf("%c ", v[j]);
printf("\n");
for (int j = 1; j <= N; ++j)
printf("%d ", len[j]);
printf("\n\n");
#endif
}
for (i = 1; i <= N; ++i)
if (v[i] == ' ')
ret += (len[i] + 1) / 2;
else
{
ret += len[i] / 2;
++ret;
}
printf("%lld\n", ret);
return 0;
}