Cod sursa(job #1946832)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 30 martie 2017 15:21:46
Problema Reguli Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cstdio>
#include <algorithm>

using namespace std;

long long v[500010];
int phi[500010];

int main ()
{
    freopen ("reguli.in", "r", stdin);
    freopen ("reguli.out", "w", stdout);

    int n;
    long long lst;

    scanf ("%d", &n);
    scanf ("%lld", &lst);

    for (int i = 2; i <= n; ++i)
    {
        long long x;
        scanf ("%lld", &x);

        v[i - 1] = x - lst;
        lst = x;
    }

    int k = 0;
    for (int i = 2; i < n; ++i)
    {
        for (; k > 0 && v[k + 1] != v[i]; k = phi[k]);

        if (v[k + 1] == v[i]) phi[i] = ++k;
    }

    k = n - 1 - phi[n - 1];
    printf ("%d\n", k);

    for (int i = 1; i <= k; ++i)
        printf ("%d\n", v[i]);

    return 0;
}