Submission #23142

# Submission time Handle Problem Language Result Execution time Memory
23142 2017-05-03T13:56:53 Z ainta Young Zebra (KRIII5_YZ) C++14
7 / 7
36 ms 6412 KB
#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

YZ.cpp: In function 'int main()':
YZ.cpp:51:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
YZ.cpp:54:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",p[i]);
                         ^
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6412 KB Output is correct
2 Correct 36 ms 6412 KB Output is correct
3 Correct 33 ms 6412 KB Output is correct
4 Correct 29 ms 6412 KB Output is correct
5 Correct 29 ms 6412 KB Output is correct
6 Correct 33 ms 6412 KB Output is correct
7 Correct 29 ms 6412 KB Output is correct
8 Correct 33 ms 6412 KB Output is correct
9 Correct 29 ms 6412 KB Output is correct
10 Correct 29 ms 6412 KB Output is correct
11 Correct 33 ms 6412 KB Output is correct
12 Correct 33 ms 6412 KB Output is correct
13 Correct 33 ms 6412 KB Output is correct
14 Correct 33 ms 6412 KB Output is correct
15 Correct 26 ms 6412 KB Output is correct
16 Correct 33 ms 6412 KB Output is correct
17 Correct 26 ms 6412 KB Output is correct
18 Correct 29 ms 6412 KB Output is correct
19 Correct 36 ms 6412 KB Output is correct
20 Correct 36 ms 6412 KB Output is correct
21 Correct 23 ms 6412 KB Output is correct
22 Correct 29 ms 6412 KB Output is correct
23 Correct 36 ms 6412 KB Output is correct
24 Correct 36 ms 6412 KB Output is correct
25 Correct 26 ms 6412 KB Output is correct
26 Correct 0 ms 6412 KB Output is correct
27 Correct 0 ms 6412 KB Output is correct
28 Correct 0 ms 6412 KB Output is correct
29 Correct 0 ms 6412 KB Output is correct
30 Correct 0 ms 6412 KB Output is correct
31 Correct 0 ms 6412 KB Output is correct
32 Correct 0 ms 6412 KB Output is correct
33 Correct 0 ms 6412 KB Output is correct
34 Correct 0 ms 6412 KB Output is correct
35 Correct 0 ms 6412 KB Output is correct
36 Correct 0 ms 6412 KB Output is correct
37 Correct 0 ms 6412 KB Output is correct
38 Correct 0 ms 6412 KB Output is correct
39 Correct 0 ms 6412 KB Output is correct
40 Correct 0 ms 6412 KB Output is correct