Cod sursa(job #1819058)

Utilizator tpc2102Nguyen Tat Dat tpc2102 Data 30 noiembrie 2016 09:22:48
Problema Reguli Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.49 kb
const
        fi = 'reguli.in';
        fo = 'reguli.out';

var
        n : longint;
        c : array[1..500000] of int64;
        next : array[1..500000] of longint;

procedure kmp;
        var
                i,j : longint;
        begin
                j := 0;
                for i := 2 to n-1 do
                        begin
                                while (j > 0) and (c[j+1] <> c[i]) do
                                        j := next[j];
                                if c[j+1] = c[i] then
                                        begin
                                                inc(j);
                                                next[i] := j;
                                        end;
                        end;
        end;

procedure main;
        var
                i,res : longint;
                a,b : int64;
        begin
                read(n);
                read(a);
                for i := 1 to n-1 do
                        begin
                                read(b);
                                c[i] := b-a;
                                a := b;
                        end;
                kmp;
                res := n-1 - next[n-1];
                writeln(res);
                for i := 1 to res do
                        writeln(c[i]);

        end;

begin
        assign(input,fi);reset(input);
        assign(output,fo);rewrite(output);
        main;
        close(input);
        close(output);
end.