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 D[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
const int NROW = 507;
const int NCOL = 507;
const int N = 5007;
int numRow, numCol, n;
bitset<NCOL> ans[NROW], tmp[NROW], islands[NROW];
int res;
void process(char c) {
if (c == 'W') {
for (int i = 1; i <= numRow; ++i) {
ans[i] >>= 1;
ans[i] &= islands[i];
}
}
else if (c == 'E') {
for (int i = 1; i <= numRow; ++i) {
ans[i] <<= 1;
ans[i] &= islands[i];
}
}
else if (c == 'N') {
for (int i = 1; i <= numRow; ++i) {
ans[i] = ans[i+1] & islands[i];
}
}
else if (c == 'S') {
for (int i = numRow; i >= 1; --i) {
ans[i] = ans[i-1] & islands[i];
}
}
else {
for (int i = 1; i <= numRow; ++i) {
tmp[i] = ((ans[i]>>1) | (ans[i]<<1) | ans[i-1] | ans[i+1]) & islands[i];
}
for (int i = 1; i <= numRow; ++i) {
ans[i] = tmp[i];
}
}
// for (int i = 1; i <= numRow; ++i, cerr << '\n')
// for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
// cerr << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
// freopen("NAUTILUS.inp", "r", stdin);
// freopen("NAUTILUS.out", "w", stdout);
cin >> numRow >> numCol >> n;
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
char c; cin >> c;
islands[i][j] = c == '.';
ans[i][j] = c == '.';
}
// for (int i = 1; i <= numRow; ++i, cerr << '\n')
// for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
// cerr << '\n';
for (int i = 1; i <= n; ++i) {
char c; cin >> c;
process(c);
}
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
res += ans[i][j];
}
cout << res;
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... |