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 <bits/stdc++.h>
using namespace std;
const int N = 505;
bitset<N * N> bs, allowed, west, east;
int main() {
int r, c, m;
cin >> r >> c >> m;
auto Get = [&](int i, int j) {
return i * c + j;
};
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
char v;
cin >> v;
if (v == '.') {
bs[Get(i, j)] = allowed[Get(i, j)] = true;
}
}
}
west.set();
east.set();
for (int i = 0; i < r; i++) {
west[Get(i, 0)] = east[Get(i, c - 1)] = false;
}
string s;
cin >> s;
for (auto d : s) {
if (d == '?') {
bs = (((bs & east) << 1) | ((bs & west) >> 1) | (bs << c) | (bs >> c)) & allowed;
} else if (d == 'N') {
bs = (bs >> c) & allowed;
} else if (d == 'S') {
bs = (bs << c) & allowed;
} else if (d == 'W') {
bs = ((bs & west) >> 1) & allowed;
} else {
bs = ((bs & east) << 1) & allowed;
}
}
cout << bs.count() << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |