Submission #211811

# Submission time Handle Problem Language Result Execution time Memory
211811 2020-03-21T11:22:32 Z origami100 Nautilus (BOI19_nautilus) C++11
66 / 100
1000 ms 3200 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
  	cin.tie(0);
	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;
			}
			//cout << dp[i][j];
		}
		//cout << '\n';
	}
	//cout << '\n';
	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][k] = (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][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(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 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 8 ms 512 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 8 ms 384 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Correct 8 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 11 ms 384 KB Output is correct
19 Correct 13 ms 512 KB Output is correct
20 Correct 9 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 8 ms 512 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 8 ms 384 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Correct 8 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 11 ms 384 KB Output is correct
19 Correct 13 ms 512 KB Output is correct
20 Correct 9 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Execution timed out 1095 ms 3200 KB Time limit exceeded
23 Halted 0 ms 0 KB -