Pagini recente » Cod sursa (job #2192215) | Cod sursa (job #562883) | Cod sursa (job #568979) | Cod sursa (job #1523517) | Cod sursa (job #2472595)
#include <bits/stdc++.h>
using namespace std;
long long a[500000], aux[500000], x_curent, x_anterior, n, pos;
int main()
{
ifstream fin("reguli.in");
ofstream fout("reguli.out");
fin >> n;
fin >> x_anterior >> x_curent;
a[0] = x_curent - x_anterior;
x_anterior = x_curent;
for(long long k = 0, i = 1; i <= n - 2; i++)
{
fin >> x_curent;
a[i] = x_curent - x_anterior;
x_anterior = x_curent;
while(k > 0 && a[i] != a[k]) k = aux[k - 1];
if(a[i] == a[k]) ++k;
aux[i] = k;
}
for(pos = n - 2; pos > 0 && aux[pos] > aux[pos - 1]; --pos );
++pos;
fout << pos << '\n';
for(long long i = 0; i < pos; ++i) fout << a[i] << '\n';
}