제출 #23142

#제출 시각아이디문제언어결과실행 시간메모리
23142aintaYoung Zebra (KRIII5_YZ)C++14
7 / 7
36 ms6412 KiB
#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");
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...