Cod sursa(job #2004406)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 25 iulie 2017 19:51:33
Problema Reguli Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <iostream>
#include <cstring>
#include <fstream>
#define NMax 500025

using namespace std;

ifstream f("reguli.in");
ofstream g("reguli.out");
int v[NMax],pi[NMax],i,n,m;
void make_prefix(int n)
{
    int q=0,frst=0,lst=0,dist=0;
    for(int i=2;i<=n;i++)
    {
        while(q && v[q+1]==v[i])
            q=pi[q];
        if(v[q+1]==v[i])
            q++;
        pi[i]=q;
        if(pi[i]!=0)
        {
            if(i%(i-pi[i])==1)
            {
                if(frst==0)
                {
                    frst=q;
                    dist=i;
                }
                else
                    lst=i;
            }
        }
    }
    g<<dist<<"\n";
    for(int i=frst;i<dist;i++)
        g<<v[i]<<"\n";
}
int main()
{
    int x,y;
    f>>n;
    f>>x;
    for(i=1;i<n;i++)
    {
        f>>y;
        v[i]=y-x;
        x=y;
    }
    n=n-1;
    make_prefix(n);
}