Cod sursa(job #1819050)

Utilizator TheMastermindThe Mastermind TheMastermind Data 30 noiembrie 2016 06:22:46
Problema Reguli Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i = a, _key = b; i <= _key; ++i)
#define fordec(i,a,b) for(int i = a, _key = b; i >= _key; --i)
#define fori(i,n) for(int i = 0, _key = n; i < _key; ++i)
#define ford(i,n) for(int i = n - 1; i >= 0; --i)
#define forvct(i,v) for(int i = 0, _key = v.size(); i < _key; ++i)
#define sqr(x) x*x
#define task "reguli"
#define st first
#define nd second
#define m_p make_pair
#define p_b push_back
#define p_f push_front
#define pp_b pop_back
#define pp_f pop_front
#define sn string::npos
#define heap priority_queue
#define ll long long
#define db double
#define str string
#define oo 1000000007
#define nn 1000010

using namespace std;

int n, nxt[nn];
ll a[nn], x[nn];

ll fastread()
{
    ll res = 0;
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    for( ; '0' <= c && c <= '9'; c = getchar()) res = res * 10 + c - '0';
    return res;
}

void enter()
{
    n = fastread();
    fori(i,n) x[i] = fastread();
}

void process()
{
    n--;
    forinc(i,1,n) a[i] = x[i] - x[i-1];
    int j = 0;
    forinc(i,2,n)
    {
        while (j && a[j+1] != a[i]) j = nxt[j];
        if (a[j+1] == a[i]) nxt[i] = ++j;
    }
    cout << n - nxt[n] << "\n";
    forinc(i,1,n - nxt[n]) cout << a[i] << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen(task".in","r",stdin);
    freopen(task".out","w",stdout);
    enter();
    process();
}