Submission #55387

# Submission time Handle Problem Language Result Execution time Memory
55387 2018-07-07T06:31:59 Z 김세빈(#1545) Sandwich (JOI16_sandwich) C++11
0 / 100
7 ms 868 KB
#include <bits/stdc++.h>

using namespace std;

char str[444][444];
bool chk[444][444][2];
int K[444];
int n, m, k;

void run(int i, int j, int d)
{
	if(chk[i][j][d]) return;
	else if(chk[i][j][!d]) k = 1e9;
	
	if(k >= 1e9) return;
	
	chk[i][j][d] = 1;
	k += 2;
	
	if(str[i][j] == 'N'){
		if(d == 0){
			if(j) run(i, j-1, 0);
			if(i+1 < n) run(i+1, j, str[i+1][j] == 'Z');
		}
		else{
			if(j+1 < m) run(i, j+1, 1);
			if(i) run(i-1, j, str[i-1][j] == 'N');
		}
	}
	else{
		if(d == 0){
			if(j) run(i, j-1, 0);
			if(i) run(i-1, j, str[i-1][j] == 'N');
		}
		else{
			if(j+1 < m) run(i, j+1, 1);
			if(i+1 < n) run(i+1, j, str[i+1][j] == 'Z'); 
		}
	}
}

int main()
{
	int i, j;
	
	scanf("%d%d", &n, &m);
	
	for(i=0;i<n;i++){
		scanf("%s", str[i]);
	}
	
	for(i=0;i<n;i++){
		for(j=k=0;j<n*m;j++) chk[j/m][j%m][0] = chk[j/m][j%m][1] = 0;
		for(j=0;j<m;j++){
			if(k < 1e9 && !chk[i][j][0]) run(i, j, 0);
			K[j] = k;
		}
		
		for(j=k=0;j<n*m;j++) chk[j/m][j%m][0] = chk[j/m][j%m][1] = 0;
		for(j=m-1;j>=0;j--){
			if(k < 1e9 && !chk[i][j][1]) run(i, j, 1);
			K[j] = min(k, K[j]);
		}
		
		for(j=0;j<m;j++){
			printf("%d ", K[j] < 1e9? K[j] : -1);
		}
		printf("\n");
	}
	
	return 0;
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 4 ms 360 KB Output is correct
3 Correct 3 ms 528 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 7 ms 768 KB Output is correct
15 Correct 5 ms 868 KB Output is correct
16 Correct 6 ms 868 KB Output is correct
17 Correct 6 ms 868 KB Output is correct
18 Correct 6 ms 868 KB Output is correct
19 Correct 7 ms 868 KB Output is correct
20 Correct 7 ms 868 KB Output is correct
21 Incorrect 5 ms 868 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 4 ms 360 KB Output is correct
3 Correct 3 ms 528 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 7 ms 768 KB Output is correct
15 Correct 5 ms 868 KB Output is correct
16 Correct 6 ms 868 KB Output is correct
17 Correct 6 ms 868 KB Output is correct
18 Correct 6 ms 868 KB Output is correct
19 Correct 7 ms 868 KB Output is correct
20 Correct 7 ms 868 KB Output is correct
21 Incorrect 5 ms 868 KB Output isn't correct
22 Halted 0 ms 0 KB -