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<iostream>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int nax = 501;
char grid[nax][nax];
vector<vector<vector<int>>>dp(nax,vector<vector<int>>(nax,vector<int>(2, 0)));
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
string s;
cin >> s;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
dp[i][j][0] = (grid[i][j] == '.' ? 1 : 0);
}
}
for (int t = 1; t <= k; t++){
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (grid[i][j] == '#')continue;
dp[i][j][t % 2] = 0;
if (s[t - 1] == 'N' || s[t - 1] == '?'){
if (i != n - 1)dp[i][j][t % 2] |= dp[i + 1][j][!(t % 2)];
}
if (s[t - 1] == 'S' || s[t - 1] == '?'){
if (i)dp[i][j][t % 2] |= dp[i - 1][j][!(t % 2)];
}
if (s[t - 1] == 'E' || s[t - 1] == '?'){
if (j)dp[i][j][t % 2] |= dp[i][j - 1][!(t % 2)];
}
if (s[t - 1] == 'W' || s[t - 1] == '?'){
if (j != m - 1){
dp[i][j][t % 2] |= dp[i][j + 1][!(t % 2)];
}
}
}
}
}
int ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
ans += dp[i][j][k & 1];
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |