답안 #3145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3145 2013-08-26T07:50:51 Z club4208 토마토 (KOI13_tomato) C++
16 / 16
152 ms 12820 KB
#include <stdio.h>
 
int dt[1001][1001], level[1001][1001];
int m, n;
short queueX[1000001], queueY[1000001];
int dx[4]={-1, 1, 0, 0};
int dy[4]={0, 0, 1, -1};
 
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    scanf("%d %d", &m, &n);
    int i, j;
    int head=1, tail=0;
    int cnt=0;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            scanf("%d", &dt[i][j]);
            if(dt[i][j]==1){queueX[++tail]=i; queueY[tail]=j; level[i][j]=1;}
            if(dt[i][j]==0){cnt++;}
        }
    }

    bool check=false;
    while(head<=tail){
        int curx, cury;
        curx=queueX[head];
        cury=queueY[head];
        head++;
        for(i=0;i<4;i++){
            int ax, ay;
            ax=curx+dx[i];
            ay=cury+dy[i];
 
            if(dt[ax][ay]==0 && 1<=ax && ax<=n && 1<=ay && ay<=m){
                dt[ax][ay]=1; queueX[++tail]=ax, queueY[tail]=ay;
                level[ax][ay]=level[curx][cury]+1;
                cnt--;
                if(cnt==0){printf("%d", level[ax][ay]-1); check=true;}
            }
        }
    }
    if(!check) printf("-1");
    else return 0;
 
    return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12820 KB Output is correct
2 Correct 0 ms 12820 KB Output is correct
3 Correct 0 ms 12820 KB Output is correct
4 Correct 0 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12820 KB Output is correct
2 Correct 0 ms 12820 KB Output is correct
3 Correct 0 ms 12820 KB Output is correct
4 Correct 0 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12820 KB Output is correct
2 Correct 0 ms 12820 KB Output is correct
3 Correct 0 ms 12820 KB Output is correct
4 Correct 0 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12820 KB Output is correct
2 Correct 4 ms 12820 KB Output is correct
3 Correct 0 ms 12820 KB Output is correct
4 Correct 0 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12820 KB Output is correct
2 Correct 0 ms 12820 KB Output is correct
3 Correct 4 ms 12820 KB Output is correct
4 Correct 4 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12820 KB Output is correct
2 Correct 4 ms 12820 KB Output is correct
3 Correct 0 ms 12820 KB Output is correct
4 Correct 4 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 12820 KB Output is correct
2 Correct 28 ms 12820 KB Output is correct
3 Correct 16 ms 12820 KB Output is correct
4 Correct 8 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12820 KB Output is correct
2 Correct 56 ms 12820 KB Output is correct
3 Correct 8 ms 12820 KB Output is correct
4 Correct 8 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12820 KB Output is correct
2 Correct 100 ms 12820 KB Output is correct
3 Correct 12 ms 12820 KB Output is correct
4 Correct 56 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 12820 KB Output is correct
2 Correct 152 ms 12820 KB Output is correct
3 Correct 124 ms 12820 KB Output is correct
4 Correct 92 ms 12820 KB Output is correct