Pagini recente » Cod sursa (job #407388) | Cod sursa (job #345901) | Cod sursa (job #870755) | Cod sursa (job #146686) | Cod sursa (job #2795398)
#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;
const int NMAX = 1000000;
int dpRmax[NMAX * 2 + 2];
char s[NMAX*2 + 1];
inline int mymin(int a, int b);
int main()
{
int n, ccur, rcur, cnou, rnou, lmax;
long long sum = 0;
char ch;
s[0] = '&';
s[1] = '*';
n = 2;
FILE *fin = fopen("pscpld.in", "r");
while (isalpha(ch = fgetc(fin)))
{
s[n++] = ch;
s[n++] = '*';
}
fclose(fin);
ccur = rcur = 0;
for (cnou = 2; cnou < n; cnou++)
{
if (ccur + rcur <= cnou)
rnou = 0;
else
rnou = mymin(dpRmax[cnou], (ccur << 1) - cnou);
while (s[cnou + rnou] == s[cnou - rnou])
rnou++;
rnou--;
dpRmax[cnou] = rnou;
sum += (long long)((rnou + 1) >> 1);
if (lmax < rnou)
lmax = rnou;
if (cnou + rnou > ccur + rcur)
{
ccur = cnou;
rcur = rnou;
}
}
FILE *fout = fopen("pscpld.out", "w");
fprintf(fout, "%lld", sum);
fclose(fout);
return 0;
}
inline int mymin(int a, int b)
{
if (a < b)
return a;
return b;
}