Cod sursa(job #3329019)

Utilizator BiceaToader David Stefan Bicea Data 11 decembrie 2025 16:10:52
Problema Prefix Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("prefix.in");
ofstream fout("prefix.out");
const int lim = 2e6 + 5;
int n, m, lps[lim], v[1005], t,w;
char a[lim] ,b[lim];
void precalc()
{
    int k = 0;
    for (int i = 2; i <= n ; ++i)
    {
        while (k && a[k] != a[i - 1]) k = lps[k];
        if (a[k] == a[i - 1]) k++;
        lps[i] = k;
        if(!i%(i-lps(i)))
          w=max(w,i-lps(i));
    }
}
int main()
{f>>t
for(int i=1;i<=t;++i)
   {fin >> a;
    n = strlen(a);
    w=0;
    precalc();
    g<<w<<'\n';;
   }
    return 0;
}