This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
using namespace std;
int H, W, N; char c[109][109];
string S;
bool used[109][109], used2[109][109];
int main() {
cin >> H >> W >> N;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) cin >> c[i][j];
}
cin >> S;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
if (c[i][j] == '#') used[i][j] = false;
else used[i][j] = true;
}
}
for (int i = 0; i < N; i++) {
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
int dir = -1;
if (S[i] == 'E') dir = 0;
if (S[i] == 'S') dir = 1;
if (S[i] == 'W') dir = 2;
if (S[i] == 'N') dir = 3;
for (int t = 0; t < 4; t++) {
if (dir == -1 || dir == t) {
for (int j = 1; j <= H; j++) {
for (int k = 1; k <= W; k++) {
if (used[j][k] == true) used2[j + dx[t]][k + dy[t]] = true;
}
}
}
}
for (int j = 1; j <= H; j++) {
for (int k = 1; k <= W; k++) {
if (c[j][k] == '.' && used2[j][k] == true) { used[j][k] = true; }
else used[j][k] = false;
used2[j][k] = false;
}
}
}
int cnt = 0;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
if (used[i][j] == true) cnt++;
}
}
cout << cnt << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |