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;
using ll = long long;
const int N = 505;
int n, m, k;
char c[N][N];
bitset<N> init[N];
bitset<N> dp[N][2];
string s;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
if (c[i][j] == '.') init[i].set(j);
}
dp[i][1] = init[i];
}
cin >> s;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
dp[j][0] = dp[j][1];
dp[j][1].reset();
}
for (int j = 1; j <= n; j++) {
if (s[i - 1] == 'W') dp[j][1] |= (dp[j][0] >> 1);
if (s[i - 1] == 'E') dp[j][1] |= (dp[j][0] << 1);
if (s[i - 1] == 'N') dp[j][1] |= dp[j + 1][0];
if (s[i - 1] == 'S') dp[j][1] |= dp[j - 1][0];
if (s[i - 1] == '?') {
dp[j][1] |= (dp[j][0] >> 1);
dp[j][1] |= (dp[j][0] << 1);
dp[j][1] |= dp[j + 1][0];
dp[j][1] |= dp[j - 1][0];
}
dp[j][1] &= init[j];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) ans += dp[i][1].count();
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |