Pagini recente » Cod sursa (job #1651782) | Cod sursa (job #282962) | Cod sursa (job #569494) | Cod sursa (job #219722) | Cod sursa (job #18920)
Cod sursa(job #18920)
#include <cstdio>
const int NMAX = 524288;
int N, sol;
long long V[NMAX];
int pi[NMAX];
void read() {
FILE *fin = fopen("reguli.in", "rt");
long long last, current;
int i;
fscanf(fin, " %d", &N);
fscanf(fin, " %lld", &last);
--N;
for (i = 0; i < N; ++i) {
fscanf(fin, " %lld", ¤t);
V[i] = current - last;
last = current;
}
fclose(fin);
}
void chimp() {
int i, j;
for (j = 0, i = 2; i <= N; ++i) {
while (j > 0 && V[j] != V[i - 1]) j = pi[j];
if (V[j] == V[i - 1]) ++j;
pi[i] = j;
}
sol = N - pi[N];
}
void write() {
FILE *fout = fopen("reguli.out", "wt");
int i;
fprintf(fout, "%d\n", sol);
for (i = 0; i < sol; ++i)
fprintf(fout, "%lld\n", V[i]);
fclose(fout);
}
int main() {
read();
chimp();
write();
return 0;
}