Pagini recente » Cod sursa (job #1550780) | Cod sursa (job #12735) | Statistici Sabin Huiban (Abinatore) | Cod sursa (job #32268) | Cod sursa (job #915949)
Cod sursa(job #915949)
#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 Left,int Right,int Ref)
{
for ( P[Ref] += A[Ref] != '#'; A[--Left] == A[++Right] ; )
P[Ref] += 2 * ( A[Left] != '#' );
Left++ , Right --;
}
#define Lung (Right-Poz)
#define Pair(x) ( x - Ref > 0 ? Ref - ( x - Ref ) : Ref + ( Ref - x ) )
int main()
{
char in[Nmax>>1]; memset(in,0,sizeof(in));
F.getline(in,Nmax>>1,'\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;
for ( ++Poz; Poz < Right ;++Poz )
{
if ( Lung > P[ Pair(Poz) ] )
P[Poz] = P[ Pair(Poz) ];
else
{
int Left2 = Ref , 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);
}
}
int Sol = 0;
for (int i=1;i<=N;++i)
Sol += (P[i]+1) / 2;
G<<Sol<<'\n';
}