Mai intai trebuie sa te autentifici.
Cod sursa(job #2756390)
| Utilizator | Data | 31 mai 2021 13:41:20 | |
|---|---|---|---|
| Problema | Prefix | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.86 kb |
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
ifstream f("prefix.in");
ofstream g("prefix.out");
const int nmax = 1e6 + 5;
int t;
int main()
{
f >> t;
while (t--) {
string s;
f >> s;
int n = s.size();
vector <int> pi(n);
for (int i = 1; i < n; ++i) {
int j = pi[i - 1];
while (j > 0 && s[j] != s[i]) {
j = pi[j - 1];
}
if (s[j] == s[i]) {
j++;
}
pi[i] = j;
}
int maxi = 0;
for (int i = n - 1; i > 0; --i) {
if (pi[i] == 0) continue;
if ((i + 1) % (i + 1 - pi[i]) == 0) {
maxi = i + 1;
break;
}
}
g << maxi << '\n';
}
return 0;
}