Cod sursa(job #115846)

Utilizator goguGogu Marian gogu Data 17 decembrie 2007 02:35:25
Problema Multiplu Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <cstdio>
#define MaxN (1<<21)
#define c(i, j) ((i)*b+(j))

int n, nr, a, b, t[MaxN], cd[MaxN];
char ok[MaxN], cif[MaxN];

void test(int r1, int r2, int T, int c){
     int cod = c(r1, r2);
     if (!ok[cod]){
        t[cod] = T;
        cif[cod] = c;
        ok[cod] = 1;
        cd[nr++] = c(r1, r2);
     }
}

void expand(int x, int y){
     int r1=(10*x)%a, r2=(10*y)%b;
     test(r1, r2, c(x, y), 0);
     test((r1+1)%a, (r2+1)%b, c(x, y), 1);
}

void refa(int c){
     if (c!=c(1, 1)) refa(t[c]);
     printf("%d", cif[c]);
}

int main()
{
    freopen("multiplu.in", "r", stdin);
    freopen("multiplu.out", "w", stdout);
    scanf("%d %d", &a, &b);
    cd[nr++] = c(1,1);
    ok[c(1,1)]=0;
    cif[c(1,1)]=1;
    int j=0;
    while (!ok[0] && j<nr){
          expand(cd[j]/b, cd[j]%b);
          j++;
    }
    refa(0);
}