Cod sursa(job #1725168)
| Utilizator | Data | 5 iulie 2016 07:54:51 | |
|---|---|---|---|
| Problema | Prefix | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
char str[2000000];
int PI[2000000];
int main() {
freopen("prefix.in", "r", stdin);
freopen("prefix.out", "w", stdout);
int t;
cin >> t;
while(t--) {
cin >> (str + 1);
PI[0] = -1;
int ans = 0;
for(int i = 1; str[i]; ++i) {
int j = PI[i - 1];
while(j != -1 && str[j + 1] != str[i])
j = PI[j];
PI[i] = j + 1;
if(2 * PI[i] < i) continue;
if(i % (i - PI[i]) == 0)
ans = i;
}
cout << ans << '\n';
}
return 0;
}