Cod sursa(job #2184275)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 23 martie 2018 21:44:18
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<fstream>
using namespace std;
ifstream in ("curcubeu.in");
ofstream out ("curcubeu.out");
int n,mod,ant,a[1000001],b[1000001],c[1000001],culoare[1000001],nxt[1000001];
int main (void) {
    in >> n >> a[1] >> b[1] >> c[1];
    mod = n;
    n --;
    for (int i = 2; i <= n; i ++) {
        a[i] = (1LL*a[i-1] * i) % mod;
        b[i] = (1LL*b[i-1] * i) % mod;
        c[i] = (1LL*c[i-1] * i) % mod;
        if (a[i] > b[i]) {
            swap (a[i],b[i]);
        }
    }
    for (int i = 0; i <= n; i ++) {
        nxt[i] = i+1;
    }
    for (int i = n; i >= 1; i --) {
        for (int j = 0; j <= n; j = nxt[j]) {
            if (j != 0 && a[i] <= j && j <= b[i]) {
                nxt[ant] = nxt[j];
                culoare[j] = c[i];
                ant = ant;
            }
            else {
                ant = j;
            }
        }
    }
    for (int i = 1; i <= n; i ++) {
        out << culoare[i] <<"\n";
    }
    return 0;
}