Cod sursa(job #637572)

Utilizator ProtomanAndrei Purice Protoman Data 20 noiembrie 2011 15:17:12
Problema PScPld Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int lung[2000010];

int main()
{
	ifstream cin("pscpld.in");
	ofstream cout("pscpld.out");

	string strCit, str;
	cin >> strCit;

	for (int i = 0; i < strCit.size(); i++)
	{
		str += " ";
		str += strCit[i];
	}
	str[0] = 'X';

	int maxGs = 0, mij = 0, sol = 0;
	for (int i = 1; i < str.size(); i++)
	{
		int x, y, loc = i;

		if (maxGs < i)
			maxGs = i, mij = i, lung[loc] = 1;

		lung[loc] = lung[mij - (loc - mij)];

		x = i - (lung[loc] + 1) / 2 - 1, y = i + (lung[loc] + 1) / 2 + 1;

		for (; x > 0 && y < str.size(); lung[loc]++, x--, y++)
			if (str[x] != str[y])
				break;
		
		if (isalnum(str[i]))
			sol += (lung[loc] + 1) / 2;
		else sol += lung[loc] / 2;

		if (maxGs < y - 1)
			maxGs = y - 1, mij = i;
	}

	cout << sol;

	return 0;
}