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 <bitset>
using namespace std;
const int MAXN = 501;
const int SZ = MAXN * MAXN;
bitset<SZ> empty_cell;
bitset<SZ> move_west;
bitset<SZ> move_east;
bitset<SZ> move_south;
bitset<SZ> ans;
signed main() {
int r, c, m;
cin >> r >> c >> m;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
char ch;
cin >> ch;
empty_cell[i * c + j] = (ch == '.');
if (j)
move_west[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j - 1];
}
}
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
if (j + 1 < c)
move_east[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j + 1];
if (i + 1 < r)
move_south[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j + c];
}
}
//cout << endl;
ans = empty_cell;
for (int i = 0; i < m; ++i) {
char ch;
cin >> ch;
if (ch == 'N') {
ans = (ans >> c) & empty_cell;
} else if (ch == 'W') {
ans = (ans & move_west) >> 1;
} else if (ch == 'E') {
ans = (ans & move_east) << 1;
} else if (ch == 'S') {
ans = (ans & move_south) << c;
} else {
ans = empty_cell & ((ans >> c) | ((ans & move_west) >> 1) | ((ans & move_east) << 1) | ((ans & move_south) << c));
}
//cout << endl;
//for (int l = 0; l < r; ++l) {
//for (int j = 0; j < c; ++j) {
//cout << ans[l * c + j];
//}
//cout << endl;
//}
}
cout << ans.count() << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |