This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bitset<505> dp[505][5005], sea[505];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
char mat[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
string str;
cin >> str;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
sea[i][j] = mat[i][j] == '.';
}
}
for(int i = 0; i < n; i++) {
dp[i][0] = sea[i];
}
for(int t = 0; t < k; t++) {
if (str[t] == 'N') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = dp[i+1][t] & sea[i];
}
} else if (str[t] == 'S') {
for(int i = 1; i < n; i++) {
dp[i][t+1] = dp[i-1][t] & sea[i];
}
} else if (str[t] == 'E') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = (dp[i][t] << 1) & sea[i];
}
} else if (str[t] == 'W') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = (dp[i][t] >> 1) & sea[i];
}
} else if (str[t] == '?') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = ((i+1 < n ? dp[i+1][t] : 0) |
(i-1 >= 0 ? dp[i-1][t] : 0) |
(dp[i][t] >> 1) |
(dp[i][t] << 1)) &
sea[i];
}
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
ans += dp[i][k][j];
}
}
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... |