Cod sursa(job #535925)

Utilizator ooctavTuchila Octavian ooctav Data 17 februarie 2011 22:08:48
Problema Reguli Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<vector>
using namespace std;

const char IN[] = {"reguli.in"};
const char OUT[] = {"reguli.out"};
const int INF = 1000000005;
const double PI  = 3.14159265;
const int SIRMAX = 500005;

#define II inline
#define LL long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fs first
#define ss second
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) 	for(LL i = a ; i <= b ; i++)
#define IFOR(i, a, b) 	for(int i = a ; i >= b ; i--)
#define FORIT(it, V) 	for(vector<int> :: iterator it = V.begin() ; it != V.end() ; it++)
#define all(a) a, a + 

LL N, REZ;
LL c[SIRMAX];
LL a[SIRMAX];
LL L[SIRMAX];

void citi()
{
	scanf("%lld%lld", &N, &a[0]);
	FOR(i, 1, N - 1)
	{
		scanf("%lld", &a[i]);
		c[i] = a[i] - a[i - 1];
	}
}

void lung()
{
	LL k = 0;
	FOR(i, 2, N - 1)
	{
		k = L[i - 1];
		while(k && !(c[k + 1] == c[i]))	
			k = L[k];
		if(c[k + 1] == c[i])
			k++;
		L[i] = k;
		if(k && i % (i - k) == 0 && i - k > REZ)	REZ = i - k;
	}
}

void scrie()
{
	printf("%lld\n", REZ);
	FOR(i, 1, REZ)
		printf("%lld\n", c[i]);
}

int main()
{
	freopen(IN, "r", stdin);
	freopen(OUT, "w", stdout);
	
	citi();
	lung();
	scrie();
	
	return 0;
}