Cod sursa(job #3202978)

Utilizator laurentiu.maticaMatica Laurentiu-Andrei laurentiu.matica Data 12 februarie 2024 19:56:22
Problema Reguli Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
// #include <iostream>

#include <fstream>
#include <climits>

using namespace std;

ifstream cin("reguli.in");
ofstream cout("reguli.out");

long long a[500002],n,m;
long long lps[500002];

int main()
{
	cin >> n;
	long long x, y;
	cin >> x;
	for (int i = 1; i < n; i++)
	{
		cin >> y;
		a[m++] = y - x;
		x = y;
	}
	long long q = 0;
	long long l = 0;
	for (int i = 2; i <= m; i++)
	{
		while (q && a[q] != a[i - 1])
			q=lps[q-1];
		if (a[q] == a[i - 1])
			q++;
		lps[i] = q;
	}
	cout << m-1-lps[m-1] << '\n';
	for (int i = 0; i < m - 1 - lps[m - 1]; i++)
		cout << a[i] << '\n';
	return 0;
}