Pagini recente » Cod sursa (job #333269) | Cod sursa (job #1950073) | Cod sursa (job #410223) | Cod sursa (job #1501605) | Cod sursa (job #2848578)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("pscpld.in");
ofstream fout("pscpld.out");
int n,l[2000005];
char s[1000005],a[2000005];
int main()
{
fin>>(s+1);
for(int i=1; s[i]!=0; i++)
{
a[++n]=s[i];
a[++n]='#';
}
a[n]=0;
n--;
int c,r,mir,dif;
long long ans=0;
if(a[1]!=a[3])
{
c=2;
r=2;
}
else
{
ans++;
c=2;
r=3;
}
for(int i=1; i<=n; i++) cout<<a[i];
cout<<"\n";
for(int i=3; i<n; i++)
{
mir=2*c-i;
dif=r-i;
if(dif>0)
l[i]=min(l[mir],dif);
while(i+l[i]+1<=n && i-l[i]-1>=1 && a[i-l[i]-1]==a[i+l[i]+1])
l[i]++;
cout<<l[i]<<" ";
if(i+l[i]>r)
{
r=i+l[i];
c=i;
}
ans+=l[i]/2;
}
fout<<ans+strlen(s+1)<<"\n";
return 0;
}