Pagini recente » Cod sursa (job #2700138) | Cod sursa (job #841966) | Cod sursa (job #3277426) | Cod sursa (job #565781) | Cod sursa (job #1589082)
#include <fstream>
#include <cstring>
#include <iostream>
using namespace std;
char s[1000003];
int p[1000003];
inline int Max(int x, int y)
{
if (x > y)
return x;
return y;
}
int main()
{
ifstream in("prefix.in");
ofstream out("prefix.out");
int t;
in >> t;
while (t--)
{
in >> s;
int n = strlen(s);
int maxp = 0;
for (int i = 1; i < n; i++)
if (s[i] == s[p[i-1]])
p[i] = p[i-1] + 1;
else
{
if (2 * p[i-1] >= i)
maxp = Max(maxp, (i / (i - p[i-1])) * (i - p[i-1]));
p[i] = (s[i] == s[0]);
}
if (2 * p[n-1] >= n)
maxp = Max(maxp, (n / (n - p[n-1])) * (n - p[n-1]));
out << maxp << '\n';
}
return 0;
}