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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int R, C, M;
cin >> R >> C >> M;
vector<bitset<505>> A(R, 0);
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
char c;
cin >> c;
if (c == '.') {
A[i][j] = 1;
}
}
}
string S;
cin >> S;
vector<bitset<505>> dp = A;
for (auto s : S) {
vector<bitset<505>> ndp(R, 0);
if (s == 'N' || s == '?') {
for (int i = 0; i < R - 1; i++) {
ndp[i] |= dp[i + 1];
}
}
if (s == 'S' || s == '?') {
for (int i = 1; i < R; i++) {
ndp[i] |= dp[i - 1];
}
}
if (s == 'E' || s == '?') {
for (int i = 0; i <= R + 1; i++) {
ndp[i] |= dp[i] << 1;
}
}
if (s == 'W' || s == '?') {
for (int i = 0; i < R; i++) {
ndp[i] |= dp[i] >> 1;
}
}
for (int i = 0; i < R; i++) {
ndp[i] &= A[i];
}
dp = ndp;
}
int ans = 0;
for (int i = 0; i < R; i++) {
ans += dp[i].count();
}
cout << ans << '\n';
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... |