Submission #98904

# Submission time Handle Problem Language Result Execution time Memory
98904 2019-02-27T09:45:47 Z Dullness 토마토 (3차원) (KOI13_tomato3D) C
0 / 20
113 ms 4380 KB
#include <stdio.h>
#define MAX 100*100*100+10

int board[101][101][101];
int x1, y1, x2, y2, N, M, L;
int min = 99999;
typedef struct tomato{
	int x; int y; int z;
	int day;
}TOMATO;
TOMATO queue[MAX];
int head, tail;
int dx[4] = { 1, 0, -1, 0, 0, 0 };
int dy[4] = { 0, -1, 0, 1, 0, 0 };
int dz[8] = { 0, 0, 0, 0, 1, -1 };
void enqueue(int x, int y, int z, int day);
TOMATO dequeue();
TOMATO popped;
TOMATO Next;
int main(){

	int x, y, z, cnt, i, j, k, sum;
	sum = 0; cnt = 0;
	scanf("%d %d %d", &M, &N, &L);
	for (k = 0; k < L; k++){
		for (i = 0; i < N; i++){
			for (j = 0; j < M; j++){
				scanf(" %d", &board[k + 1][i + 1][j + 1]);
				if (board[k + 1][i + 1][j + 1] == 1) enqueue(i + 1, j + 1, k +1 , 0);
			}
		}
	}
	while (head != tail){
		popped = dequeue();
		x = popped.x; y = popped.y; cnt = popped.z;
		for (i = 0; i < 6; i++){
			if (!(x + dx[i] > 0 && x + dx[i] < (N + 1))) continue;
			if (!(y + dy[i] >  0 && y + dy[i] < (M + 1))) continue;
			if (!(z + dz[i] > 0 && z + dz[i] < (L + M))) continue;
			if (board[z+dz[i]][x + dx[i]][y + dy[i]] == 1)  continue;
			if (board[z + dz[i]][x + dx[i]][y + dy[i]] == -1) continue;
			if (board[z + dz[i]][x + dx[i]][y + dy[i]] == 0){
				enqueue(x + dx[i], y + dy[i], z+ dz[i], cnt + 1);
			}
		}
	}
	min = cnt;
	for (k = 0; k < L; k++){
		for (i = 0; i < N; i++){
			for (j = 0; j < M; j++){
				if (board[k + i][i + 1][j + 1] == 0){
					min = -1; break;
				}
			}
		}
	}
	printf("%d", min);
	return 0;
}

void enqueue(int x, int y, int z, int day){
	tail++; tail %= MAX;
	queue[tail].x = x; queue[tail].y = y; queue[tail].z = z; queue[tail].day = day;
	board[z][x][y] = 1;
	return;
}

TOMATO dequeue(){
	head++; head %= MAX;
	TOMATO out;
	out.x = queue[head].x; out.y = queue[head].y; out.z = queue[head].z;
	return out;
}

Compilation message

cc.c:5:9: warning: built-in function 'y1' declared as non-function
 int x1, y1, x2, y2, N, M, L;
         ^~
cc.c:13:28: warning: excess elements in array initializer
 int dx[4] = { 1, 0, -1, 0, 0, 0 };
                            ^
cc.c:13:28: note: (near initialization for 'dx')
cc.c:13:31: warning: excess elements in array initializer
 int dx[4] = { 1, 0, -1, 0, 0, 0 };
                               ^
cc.c:13:31: note: (near initialization for 'dx')
cc.c:14:28: warning: excess elements in array initializer
 int dy[4] = { 0, -1, 0, 1, 0, 0 };
                            ^
cc.c:14:28: note: (near initialization for 'dy')
cc.c:14:31: warning: excess elements in array initializer
 int dy[4] = { 0, -1, 0, 1, 0, 0 };
                               ^
cc.c:14:31: note: (near initialization for 'dy')
cc.c: In function 'main':
cc.c:22:29: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
  int x, y, z, cnt, i, j, k, sum;
                             ^~~
cc.c:24:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &M, &N, &L);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc.c:28:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d", &board[k + 1][i + 1][j + 1]);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc.c:37:16: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]
    if (!(x + dx[i] > 0 && x + dx[i] < (N + 1))) continue;
              ~~^~~
cc.c:36:3: note: within this loop
   for (i = 0; i < 6; i++){
   ^~~
cc.c:39:12: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (!(z + dz[i] > 0 && z + dz[i] < (L + M))) continue;
          ~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 3580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 3376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 4256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 113 ms 4380 KB Output isn't correct
2 Halted 0 ms 0 KB -