Pagini recente » Cod sursa (job #1576589) | Cod sursa (job #2207686) | Cod sursa (job #147250) | Cod sursa (job #476046) | Cod sursa (job #1256147)
/*
* 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 )
{
if ( mit > i )
DP [ i ] = min ( DP [ i * 2 - id ] , mit - i ) ;
else DP [ 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;
}