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>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
char a[n + 1][m + 1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
a[i][j] = '#';
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
char b[q + 1];
for(int i = 1; i <= q; i++) {
cin >> b[i];
}
int dp[q + 1][n + 1][m + 1];
for(int i = 0; i <= q; i++) {
for(int j = 0; j <= n; j++) {
for(int k = 0; k <= m; k++) {
dp[i][j][k] = 0;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == '.') {
dp[0][i][j] = 1;
}
}
}
for(int i = 1; i <= q; i++) {
if(b[i] == '?') {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(a[j][k] == '#') {
continue;
}
if(a[j - 1][k] != '#') dp[i][j][k] |= dp[i - 1][j - 1][k];
if(a[j + 1][k] != '#') dp[i][j][k] |= dp[i - 1][j + 1][k];
if(a[j][k - 1] != '#') dp[i][j][k] |= dp[i - 1][j][k - 1];
if(a[j][k + 1] != '#') dp[i][j][k] |= dp[i - 1][j][k + 1];
}
}
}
else {
if(b[i] == 'N') {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(a[j][k] == '#') {
continue;
}
if(a[j - 1][k] != '#') dp[i][j][k] |= dp[i - 1][j - 1][k];
}
}
}
else if(b[i] == 'W') {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(a[j][k] == '#') {
continue;
}
if(a[j][k - 1] != '#') dp[i][j][k] |= dp[i - 1][j][k - 1];
}
}
}
else if(b[i] == 'S') {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(a[j][k] == '#') {
continue;
}
if(a[j + 1][k] != '#') dp[i][j][k] |= dp[i - 1][j + 1][k];
}
}
}
else {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(a[j][k] == '#') {
continue;
}
if(a[j][k + 1] != '#') dp[i][j][k] |= dp[i - 1][j][k + 1];
}
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
//cout << dp[q][i][j] << " ";
ans += dp[q][i][j];
}
//cout << endl;
}
cout << ans;
// levo ispod
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |