답안 #14239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14239 2015-05-07T11:53:29 Z moonrabbit2 토마토 (3차원) (KOI13_tomato3D) C++
20 / 20
155 ms 20612 KB
#include <cstdio>
#define MAX 100
int queue[3][MAX*MAX*MAX],check[MAX][MAX][MAX],a[MAX][MAX][MAX],top,place,m,n,h,count=1,nmax;
void queueinsert(int x,int y,int z,int c)
{
    queue[0][top]=x;
    queue[1][top]=y;
    queue[2][top++]=z;
    check[x][y][z]=c;
}
void put(int x,int y,int z)
{
int c=check[x][y][z];
    if(y-1<0||check[x][y-1][z]!=0||a[x][y-1][z]==-1);
    else queueinsert(x,y-1,z,c+1);
    if(y+1>=n||check[x][y+1][z]!=0||a[x][y+1][z]==-1);
    else queueinsert(x,y+1,z,c+1);
    if(z-1<0||check[x][y][z-1]!=0||a[x][y][z-1]==-1);
    else queueinsert(x,y,z-1,c+1);
    if(z+1>=m||check[x][y][z+1]!=0||a[x][y][z+1]==-1);
    else queueinsert(x,y,z+1,c+1);
    if(x-1<0||check[x-1][y][z]!=0||a[x-1][y][z]==-1);
    else queueinsert(x-1,y,z,c+1);
    if(x+1>=h||check[x+1][y][z]!=0||a[x+1][y][z]==-1);
    else queueinsert(x+1,y,z,c+1);
}
int main()
{
    scanf("%d %d %d",&m,&n,&h);
    for(int i=0;i<h;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<m;k++){
                scanf("%d",&a[i][j][k]);
                if(a[i][j][k]==1)queueinsert(i,j,k,1);
            }
        }
    }
    while(m*n*h!=count){
        if(check[queue[0][place]][queue[1][place]][queue[2][place]]!=0&&a[queue[0][place]][queue[1][place]][queue[2][place]]!=-1){
            put(queue[0][place],queue[1][place],queue[2][place]);
            place++;
        }
        count++;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<m;k++){
                if(check[i][j][k]==0&&a[i][j][k]==0){
                    printf("-1");
                    return 0;
                }
                if(check[i][j][k]>nmax)nmax=check[i][j][k];
            }
        }
    }
    printf("%d",nmax-1);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 20612 KB Output is correct
2 Correct 0 ms 20612 KB Output is correct
3 Correct 0 ms 20612 KB Output is correct
4 Correct 0 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 20612 KB Output is correct
2 Correct 3 ms 20612 KB Output is correct
3 Correct 4 ms 20612 KB Output is correct
4 Correct 0 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 20612 KB Output is correct
2 Correct 0 ms 20612 KB Output is correct
3 Correct 0 ms 20612 KB Output is correct
4 Correct 0 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 20612 KB Output is correct
2 Correct 22 ms 20612 KB Output is correct
3 Correct 25 ms 20612 KB Output is correct
4 Correct 27 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 20612 KB Output is correct
2 Correct 4 ms 20612 KB Output is correct
3 Correct 25 ms 20612 KB Output is correct
4 Correct 6 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 20612 KB Output is correct
2 Correct 21 ms 20612 KB Output is correct
3 Correct 37 ms 20612 KB Output is correct
4 Correct 7 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 20612 KB Output is correct
2 Correct 36 ms 20612 KB Output is correct
3 Correct 71 ms 20612 KB Output is correct
4 Correct 18 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 20612 KB Output is correct
2 Correct 93 ms 20612 KB Output is correct
3 Correct 63 ms 20612 KB Output is correct
4 Correct 93 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 20612 KB Output is correct
2 Correct 125 ms 20612 KB Output is correct
3 Correct 125 ms 20612 KB Output is correct
4 Correct 154 ms 20612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 20612 KB Output is correct
2 Correct 57 ms 20612 KB Output is correct
3 Correct 155 ms 20612 KB Output is correct
4 Correct 62 ms 20612 KB Output is correct