Pagini recente » Cod sursa (job #914729) | Cod sursa (job #2138821) | Cod sursa (job #1924332) | Cod sursa (job #774010) | Cod sursa (job #1256149)
/*
* Code by Spiromanul
*/
#include <fstream>
#include <cstring>
const char IN [ ] = "pscpld.in" ;
const char OUT [ ] = "pscpld.out" ;
const int MAX = 1000014 ;
using namespace std;
ifstream fin ( IN ) ;
ofstream fout ( OUT ) ;
char sir [ MAX ] ;
char psc [ MAX + MAX ] ;
int DP [ MAX + MAX ] ;
int main( )
{
fin >> sir ;
int l = strlen ( sir ) ;
int n = 2 ;
psc [ 0 ] = '@' ;
psc [ 1 ] = '$' ;
for ( int i = 0 ; i < l ; ++ i )
{
psc [ n ++ ] = sir [ i ] ;
psc [ n ++ ] = '$' ;
}
psc [ n ] = '\0' ;
DP [ 1 ] = DP [ 0 ] = 1 ;
int mit = 1 ;
int id = 1 ;
for ( int i = 2 ; i < n ; ++ i )
{
DP [ i ] = ( mit > i ) ? min ( DP [ i * 2 - id ] , mit - i ) : 1 ;
while ( psc [ i + DP [ i ] ] == psc [ i - DP [ i ] ] )
DP [ i ] ++ ;
if ( i + DP [ i ] > mit )
{
mit = i + DP [ i ] ;
id = i ;
}
}
long long sol = 0 ;
for ( int i = 1 ; i < n ; ++ i )
sol += DP [ i ] >> 1 ;
fout << sol << '\n' ;
return 0;
}