Cod sursa(job #2512)

Utilizator tm_raduToma Radu tm_radu Data 17 decembrie 2006 15:23:20
Problema PScPld Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <stdio.h>

int i, j, n, k;
char c;
int a[1000001];
int x[2000005];
long long int sol;

int main()
{
    freopen("pscpld.in", "r", stdin);
	freopen("pscpld.out", "w", stdout);
    scanf("%c", &c);
    while ( c <= 'z' && c >= 'a' )
    {
        k++;
        a[k] = (int)(c-'a'+1);
		x[2*k-1] = 1;
        c = '#';
        scanf("%c", &c);
	}
	n = k;
    for ( i = 1; i <= 2*n; i++ )
	{
        if ( i % 2 == 1 )
        {
			j = x[i]+2;
			while ( 1 )
			{
				if ( a[(i-j)/2+1] == a[(i+j)/2] )
				{
					x[i] += 2;
					x[i+j-1] = x[i-j+1];
					x[i+j-2] = x[i-j+2];
				}
				else break;
				j+=2;
			}
		}
		else
		{
			j = x[i]+2;
			while ( 1 )
			{
				if ( a[(i-j)/2+1] == a[(i+j)/2] )
				{
					x[i] += 2;
					x[i+j-1] = x[i-j+1];
					x[i+j-2] = x[i-j+2];
				}
				else break;
				j+=2;
            }
        }
	}
	sol = 0;
	for ( i = 1; i <= 2*n; i++ )
		if ( i % 2 == 1 )
			sol += (x[i]+1)/2;
		else
			sol += x[i]/2;
    printf("%lld\n", sol);
	return 0;
}