Cod sursa(job #1563574)

Utilizator serbanSlincu Serban serban Data 6 ianuarie 2016 12:04:50
Problema Reguli Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

vector<long long> r;

int main()
{
    ifstream f("reguli.in");
    ofstream g("reguli.out");

    int n, m = 1;
    long long x1, x2; f >> n >> x1 >> x2;
    r.push_back(x2 - x1); x1 = x2;
    for(int i = 2; i < n; i ++) {
        f >> x2;
        if(r[ (i - 1) % m] != (x2 - x1)) {
            int in = m, aux = i - 1;
            while(m < aux) {
                for(int j = 0; j < in && m < aux; j ++, m ++)
                    r.push_back(r[j]);
            }
            r.push_back(x2 - x1); m ++;
        }
        x1 = x2;
    }
    g << r.size() << "\n";
    for(int i = 0; i < r.size(); i ++) g << r[i] << "\n";
    return 0;
}