Cod sursa(job #2288923)
Utilizator | Data | 24 noiembrie 2018 09:37:32 | |
---|---|---|---|
Problema | Prefix | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("prefix.in");
ofstream g("prefix.out");
int l,i,j,k,n,p[1000005];
char c[1000005];
int main()
{
f>>l;
for(i=1;i<=l;i++)
{
f>>c+1;
n=strlen(c+1);
k=0;
for(j=2;j<=n;j++)
{
for(;k!=0&&c[k+1]!=c[j];)k=p[k];
if(c[k+1]==c[j])k++;
p[j]=k;
}
for(j=n;j>=1;j--)
{
if(p[j]!=0&&j%(j-p[j])==0)
{
g<<j<<'\n';
break;
}
if(j==1)g<<"0"<<'\n';
}
}
return 0;
}