| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 23142 | ainta | Young Zebra (KRIII5_YZ) | C++14 | 36 ms | 6412 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<algorithm>
int n, m, Q[321000][2], head, tail, Num[410][410][2], C[410][410], chk, Res[410][410];
char p[410][410];
int MakeP(int x, int pv){
    int t = n;
    if(pv==1)t = m;
    if(x<0) x += (-x+t)/t*t;
    x%=t;
    return x;
}
void Ins(int x, int y){
    int tx = MakeP(x,0), ty = MakeP(y,1);
    if(Num[tx][ty][0] > -1e7){
        if(Num[tx][ty][0]!=x||Num[tx][ty][1]!=y)chk = -1;
        return;
    }
    Num[tx][ty][0] = x, Num[tx][ty][1] = y;
    tail++;
    Q[tail][0] = x, Q[tail][1] = y;
}
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
void Make(int x, int y){
    int tx = MakeP(x,0), ty = MakeP(y,1);
    int i, ttx, tty;
    for(i=0;i<4;i++){
        ttx = (tx+n+dx[i])%n;
        tty = (ty+m+dy[i])%m;
        if(p[tx][ty] == p[ttx][tty]){
            Ins(x+dx[i], y+dy[i]);
        }
    }
}
void Do(int x, int y){
    chk = 0;
    head = tail = 0;
    Ins(x,y);
    while(head < tail){
        head++;
        x = Q[head][0], y = Q[head][1];
        Make(x,y);
    }
    int i;
    if(!chk)chk = tail;
    for(i=1;i<=tail;i++){
        x = MakeP(Q[i][0], 0), y = MakeP(Q[i][1], 1);
        Res[x][y] = chk;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    int i, j;
    for(i=0;i<n;i++){
        scanf("%s",p[i]);
        for(j=0;j<m;j++){
            Num[i][j][0] = Num[i][j][1] = -1e8;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(Num[i][j][0] < -1e7){
                Do(i,j);
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            printf("%d ",Res[i][j]);
        }
        printf("\n");
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
