#include <bits/stdc++.h>
using namespace std;
int r, c, m;
string a[100];
bool f(int x, int y) {
if(x >= 0 && x < r && y >= 0 && y < c && a[x][y] == '.') {
return true;
}
return false;
}
int main() {
cin >> r >> c >> m;
bool vis[r][c] {};
for(int i = 0; i < r; i++) {
cin >> a[i];
for(int j = 0; j < c; j++) {
if(a[i][j] == '.') {
vis[i][j] = 1;
}
}
}
string s;
cin >> s;
bool Vis[r][c] {};
for(char X : s) {
int x, y;
if(X == 'W') {
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
x = i;
y = j;
if(vis[x][y]){
y--;
if(f(x, y)) {
Vis[x][y] = 1;
}
}
}
}
}
if(X == 'E') {
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
x = i;
y = j;
if(vis[x][y]) {
y++;
if(f(x, y)) {
Vis[x][y] = 1;
}
}
}
}
}
if(X == 'N') {
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
x = i;
y = j;
if(vis[x][y]){
x--;
if(f(x, y)) {
Vis[x][y] = 1;
}
}
}
}
}
if(X == 'S') {
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
x = i;
y = j;
if(vis[x][y]) {
x++;
if(f(x, y)) {
Vis[x][y] = 1;
}
}
}
}
}
if(X == '?') {
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
x = i;
y = j;
if(vis[x][y]) {
if(f(x + 1, y)) {
Vis[x + 1][y] = 1;
}
if(f(x - 1, y)) {
Vis[x - 1][y] = 1;
}
if(f(x, y + 1)) {
Vis[x][y + 1] = 1;
}
if(f(x, y - 1)) {
Vis[x][y - 1] = 1;
}
}
}
}
}
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
vis[i][j] = Vis[i][j];
Vis[i][j] = 0;
}
}
}
int S = 0;
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
if(vis[i][j]) {
S++;
}
}
}
cout << S << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
480 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
7 ms |
348 KB |
Output is correct |
14 |
Correct |
9 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
3 ms |
448 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
480 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
7 ms |
348 KB |
Output is correct |
14 |
Correct |
9 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
3 ms |
448 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |