// Alir3za.Zar3 -> Shiraz , Iran
#include <bits/stdc++.h>
using namespace std;
#define loop(i , l , r) for (int i=l; i<=r; i+=1)
#define arc(i , r , l) for (int i=r; i>=l; i-=1)
const int N = 5e2+7;
bool dp[2][N][N];
string s,t[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int r,c,m; cin >> r >> c >> m;
vector<pair<int,int>> q;
loop(i,0,r-1)
{
cin >> t[i];
loop(j,0,c-1)
{
if (t[i][j]=='.')
{
dp[0][i][j]=1;
q.push_back({i,j});
}
}
}
cin >> s; int T=0;
loop(k,0,m-1)
{
T = 1-T;
for (auto [i,j] : q)
{
dp[T][i][j] = false;
if (i>0 and dp[1-T][i-1][j] and (s[k]=='S' or s[k]=='?'))
{
dp[T][i][j] = true;
}
if (j>0 and dp[1-T][i][j-1] and (s[k]=='E' or s[k]=='?'))
{
dp[T][i][j] = true;
}
if (i<r-1 and dp[1-T][i+1][j] and (s[k]=='N' or s[k]=='?'))
{
dp[T][i][j] = true;
}
if (j<c-1 and dp[1-T][i][j+1] and (s[k]=='W' or s[k]=='?'))
{
dp[T][i][j] = true;
}
}
}
int out = 0;
loop(i,0,r-1)
{
loop(j,0,c-1)
{
out += dp[T][i][j];
}
}
cout << out << '\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... |