답안 #3144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3144 2013-08-26T07:50:26 Z club4208 토마토 (KOI13_tomato) C++
0 / 16
0 ms 12812 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 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 12812 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -