Pagini recente » Cod sursa (job #1585965) | Cod sursa (job #2352464) | Cod sursa (job #1285518) | Cod sursa (job #785814) | Cod sursa (job #1202270)
# include <fstream>
# include <cstring>
# include <algorithm>
# include <vector>
# define dim 500005
using namespace std;
ifstream f("reguli.in");
ofstream g("reguli.out");
long long a[ dim ];
int p[ dim ];
int n;
void citire()
{
int i;
long long curent, anterior;
f >> n;
for ( i = 1 ; i <= n ; i++ )
{
f >> curent;
if ( i == 1 )
{
anterior = curent;
}
else
{
a[ i - 1 ] = curent - anterior;
anterior = curent;
}
}
//for ( i = 1 ; i < n ; i++ )
// g << a[ i ] << " ";
//g << "\n";
}
void prefix()
{
int i, q = 0;
p[ i ] = 0;
for ( i = 2 ; i < n ; i++ )
{
while ( q > 0 && a[ q + 1 ] != a[ i ] )
q = p[ q ];
if ( a[ q + 1 ] == a[ i ] )
q++;
p[ i ] = q;
}
// for ( i = 1 ; i < n ; i++ )
// g << p[ i ] << " ";
// g << "\n";
}
void rezolva()
{
int indice = n - 1, i;
for ( i = n - 2 ; i >= 2 ; i-- )
{
//if ( p[ n - 1 ] < n - i - 1 )
// indice = min( indice, i );
if ( i % ( i - p[ i ] ) == 0 && p[ i ] != 0 && p[ n - 1 ] > n - i - 1 )
indice = min( ( i - p[ i ] ), indice );
}
g << indice << "\n";
for ( i = 1 ; i <= indice; i++ )
g << a[ i ] << "\n";
}
int main()
{
citire();
prefix();
rezolva();
return 0;
}