Cod sursa(job #1951162)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 3 aprilie 2017 14:29:55
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<fstream>
#define DIM 1000005
using namespace std;
int n, i, j;
int a[DIM], b[DIM], c[DIM], nxt[DIM], sol[DIM];
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int main(){
    fin>> n >> a[1] >> b[1] >> c[1];
    for(i = 2; i < n; i++){
        a[i] = (a[i - 1] * 1LL * i) % n;
        b[i] = (b[i - 1] * 1LL * i) % n;
        c[i] = (c[i - 1] * 1LL * i) % n;
    }
    for(i = n - 1; i >= 1; i--){
        if(a[i] > b[i]){
            swap(a[i], b[i]);
        }
        j = a[i];
        while(j <= b[i]){
            if(sol[j] != 0){
                j = nxt[j];
            }
            else{
                sol[j] = c[i];
                nxt[j] = b[i] + 1;
                j++;
            }
        }
    }
    for(i = 1; i < n; i++){
        fout<< sol[i] <<"\n";
    }
    return 0;
}