Cod sursa(job #3322167)

Utilizator octavurlurleteanu alexandru octavian octavurl Data 12 noiembrie 2025 22:36:56
Problema Reguli Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back(x)
using namespace std;

ifstream fin ( "reguli.in" ) ;
ofstream fout ( "reguli.out" ) ;

const ll nmax = 5e5 ;
ll pi[nmax+5];
ll nxt()
{
    ll x;
    fin >> x;
    return x;
}
void les(vector<ll>s)
{
  ll n = s.size();
  ll i = 1 , lg = 0 ;
  while ( i < n )
  {
    if ( s[lg] == s[i] )
        pi[i++]=++lg;
    else if ( lg )
        lg = pi[lg-1];
    else
        pi[i++]=0;
  }
}

signed main()
{
    ll n ;
    fin >> n ;
    ll prevx = nxt();
    vector<ll>sum;
    for ( ll i = 1 ; i < n ; ++ i )
    {
    ll y = nxt();
    sum.pb(y-prevx); prevx=y;
    }
    --n;
    les(sum);
    if ( !pi[n-1] )
    {
    fout << n << '\n';
    for ( auto it : sum )
        fout << it << '\n' ;
    return 0;
    }
    fout << n - pi[n-1] << '\n';
    for ( ll i = 0 ; i < n - pi[n-1] ; ++ i )
        fout << sum[i] << '\n' ;
    return 0;
}