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;
const int nx=505;
int r, c, m, dx[4]={1, 0, 0, -1}, dy[4]={0, 1, -1, 0}, en[100], cnt;
char mp[nx][nx];
bool dp[2][nx][nx];
string s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
en['N']=1; en['W']=0; en['E']=3; en['S']=2;
cin>>r>>c>>m;
for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) cin>>mp[i][j], dp[0][i][j]=(mp[i][j]=='.');
cin>>s;
for (int i=1; i<=m; i++)
{
int cr=i%2, pv=1-cr;
for (int j=1; j<=r; j++)
{
for (int k=1; k<=c; k++)
{
if (mp[j][k]!='#')
{
if (s[i-1]=='?') for (int l=0; l<4; l++) dp[cr][j][k]|=dp[pv][j+dy[l]][k+dx[l]];
else dp[cr][j][k]=dp[pv][j+dy[en[s[i-1]]]][k+dx[en[s[i-1]]]];
}
if (i==m&&dp[cr][j][k]) cnt++;
}
}
for (int j=1; j<=r; j++) for (int k=1; k<=c; k++) dp[pv][j][k]=0;
}
cout<<cnt;
}
Compilation message (stderr)
nautilus.cpp: In function 'int main()':
nautilus.cpp:28:60: warning: array subscript has type 'char' [-Wchar-subscripts]
28 | else dp[cr][j][k]=dp[pv][j+dy[en[s[i-1]]]][k+dx[en[s[i-1]]]];
| ^
nautilus.cpp:28:78: warning: array subscript has type 'char' [-Wchar-subscripts]
28 | else dp[cr][j][k]=dp[pv][j+dy[en[s[i-1]]]][k+dx[en[s[i-1]]]];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |