Cod sursa(job #1943823)

Utilizator raduzxstefanescu radu raduzx Data 28 martie 2017 20:38:09
Problema Prefix Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>

using namespace std;
ifstream f("prefix.in");
ofstream g("prefix.out");
#define p 73
#define mod 100007
#define mod 100021
#define nmax 1000010
char s[nmax];
int in1,in2,t,q,hash1,hash2,maxim,i,d,j,to;
int main()
{
    f>>t;
    for(q=1;q<=t;q++)
    {
        f>>s;
        maxim=0;
        i=1;
        while(s[i] and s[i]==s[i-1])
            i+=1;
        if(i>1)
        maxim=i;
        while(s[i])
            i+=1;
        to=i;
        if(q==4)
            d=3;
        d=2;
        while((d<<1)<=to)
        {
                i=d;
                while(i<to and s[i]==s[i-d])
                    i+=1;
                if(i/d>=2 and i/d*d>maxim)
                    maxim=i/d*d;
            d+=1;
        }
        g<<maxim<<'\n';
    }
    return 0;
}