Pagini recente » Cod sursa (job #2038108) | Cod sursa (job #2832675) | Cod sursa (job #3262182) | Cod sursa (job #3286511) | Cod sursa (job #915965)
Cod sursa(job #915965)
#include <fstream>
#include <cstring>
using namespace std;
ifstream F("pscpld.in");
ofstream G("pscpld.out");
const int Nmax = 2000010;
int N,P[Nmax];
char A[Nmax];
int Left,Right,Ref;
void Extend(int& L,int& R,int& r)
{
P[r] = max( (R-L+1) / 2 , int(A[r] != '#') );
for ( ; A[--L] == A[++R] ; )
P[r] += 2 * ( A[L] != '#' );
L++ , R--;
}
#define Lung (Right-Poz)
#define Pair(x,Ref) ( x - Ref > 0 ? Ref - ( x - Ref ) : Ref + ( Ref - x ) )
int main()
{
char in[Nmax]; memset(in,0,sizeof(in));
F.getline(in,Nmax,'\n'); int l = strlen(in);
for (int i=0;i<l;++i)
A[++N] = '#', A[++N] = in[i];
A[++N] = '#';
A[0] = 'X';
A[N+1] = 'Y';
P[1] = P[2] = 0, Left = Right = Ref = 2;
Extend(Left,Right,Ref);
for (int Poz,Start;Ref <= N; )
{
Poz = Start = Ref;
while ( Poz < Right )
{
++Poz;
if ( Lung > P[ Pair(Poz,Ref) ] )
P[Poz] = P[ Pair(Poz,Ref) ];
else
{
int Left2 = Pair(Right,Poz) , Right2 = Right;
Extend(Left2,Right2,Poz);
Left = Left2, Right = Right2, Ref = Poz;
break;
}
}
if ( Start == Ref )
{
Poz = Right+1;
Left = Right = Ref = Poz;
Extend(Left,Right,Ref);
}
}
long long Sol = 0;
for (int i=1;i<=N;++i)
Sol += 1LL * (P[i]+1) / 2;
G<<Sol<<'\n';
}