Cod sursa(job #3204827)

Utilizator alexandraiacobelAlexandra Iacob alexandraiacobel Data 17 februarie 2024 18:02:04
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");

int n,m,i,j,a,b,c,st,dr,father[100005],sol[1000005];
struct s
{
    int c,b,a;
}color[1000005];

int main()
{
     fin>>n>>a>>b>>c;

     color[1].a=a , color[1].b=b , color[1].c = c;

     for(i=2;i<n;i++)
     {
         a = color[i].a = a*i%n;
         b = color[i].b = b*i%n;
         c = color[i].c = c*i%n;
     }

     for(i=n-1;i>=1;i--)
     {
          st = min(color[i].a, color[i].b);
          dr = max(color[i].a, color[i].b);

         for(j = st;j<=dr && j<n;j++)
         {
             if(!sol[j])
             {
               sol[j] = color[i].c;
               father[j] = dr+1; ///!
             }
             else
                j = father[j];

         }
     }
    for(i=1; i<n;i++)
        fout<<sol[i]<<'\n';

    return 0;
}