Submission #211807

# Submission time Handle Problem Language Result Execution time Memory
211807 2020-03-21T10:50:44 Z origami100 Nautilus (BOI19_nautilus) C++11
0 / 100
6 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
	int r, c, m;
	cin >> r >> c >> m;
	int grid[r][c], dp[r][c];
	for(int i = 0; i < r; i++){
		string s;
		cin >> s;
		for(int j = 0; j < c; j++){
			if(s[j] == '.'){
				grid[i][j] = 1;
				dp[i][j] = 1;
			}else{
				grid[i][j] = 0;
				dp[i][j] = 0;
			}
		}
	}
	for(int i = 0; i < m; i++){
		char ins;
		cin >> ins;
		switch(ins){
			case 'N':
				for(int j = 0; j < r - 1; j++){
					for(int k = 0; k < c; k++){
						dp[j][k] = (grid[j][k] == 1 && dp[j + 1][k] == 1)?1:0;
					}
				}
				for(int k = 0; k < c; k++) dp[r - 1][k] = 0;
				break;
			case 'S':
				for(int j = r - 1; j > 0; j--){
					for(int k = 0; k < c; k++){
						dp[j][k] = (grid[j][k] == 1 && dp[j - 1][k] == 1)?1:0;
					}
				}
				for(int k = 0; k < c; k++) dp[0][k] = 0;
				break;
			case 'W':
				for(int j = 0; j < r; j++){
					for(int k = 0; k < c - 1; k++){
						dp[j][j] = (grid[j][k] == 1 && dp[j][k + 1] == 1)?1:0;
					}
				}
				for(int k = 0; k < r; k++) dp[k][c - 1] = 0;
				break;
			case 'E':
				for(int j = 0; j < r; j++){
					for(int k = c - 1; k > 0; k--){
						dp[j][k] = (grid[j][k] == 1 && dp[j][k - 1] == 1)?1:0;
					}
				}
				for(int k = 0; k < r; k++) dp[k][0] = 0;
				break;
			case '?':
				int prev[r][c];
				for(int j = 0; j < r; j++){
					for(int k = 0; k < c; k++){
						prev[j][k] = dp[j][k];
					}
				}
				for(int j = 0; j < r; j++){
					for(int k = 0; k < c; k++){
						if(grid[j][k] == 1){
							if(j == 0){
								if(k == 0) dp[j][k] = (prev[j + 1][k] == 1 || prev[j][k + 1] == 1)?1:0;
								else if(k == c - 1) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1)?1:0;
								else dp[j][k] = (prev[j + 1][k] == 1 || prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0;
							}else if(j == r - 1){
								if(k == 0) dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k + 1] == 1)?1:0;
								else if(k == c - 1) dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k - 1] == 1)?1:0;
								else dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0;
							}else{
								if(k == 0) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k + 1] == 1)?1:0;
								else if(k == c - 1) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k - 1] == 1)?1:0;
								else dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0;
							}
						}
					}
				}
				break;
		}
		/*for(int j = 0; j < r; j++){
			for(int k = 0; k < c; k++){
				cout << dp[j][k];
			}
			cout << '\n';
		}
		cout << '\n';*/
	}
	int cnt = 0;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			if(dp[i][j] == 1) cnt++;
		}
	}
	cout << cnt;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -