#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int n,m,p,cnt;
char arr[501][501];
int vis[501][501],dp[501][501][701];
string s;
void solve(int i,int j,int k){
if(i>=n||j>=m||i<0||j<0||arr[i][j]=='#'||dp[i][j][k]==1||k>700) return;
if(k==p){
if(vis[i][j]!=1) cnt++;
vis[i][j]=1;
return;
}
dp[i][j][k]=1;
if(s[k]=='N'||s[k]=='?') solve(i-1,j,k+1);
if(s[k]=='S'||s[k]=='?') solve(i+1,j,k+1);
if(s[k]=='E'||s[k]=='?') solve(i,j+1,k+1);
if(s[k]=='W'||s[k]=='?') solve(i,j-1,k+1);
return;
}
signed main()
{
cin>>n>>m>>p;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) cin>>arr[i][j];
}
cin>>s;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) solve(i,j,0);
}
cout<<cnt<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
48344 KB |
Output is correct |
2 |
Correct |
16 ms |
33752 KB |
Output is correct |
3 |
Correct |
13 ms |
25180 KB |
Output is correct |
4 |
Correct |
9 ms |
17500 KB |
Output is correct |
5 |
Correct |
5 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
48344 KB |
Output is correct |
2 |
Correct |
16 ms |
33752 KB |
Output is correct |
3 |
Correct |
13 ms |
25180 KB |
Output is correct |
4 |
Correct |
9 ms |
17500 KB |
Output is correct |
5 |
Correct |
5 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
39 ms |
49080 KB |
Output is correct |
8 |
Correct |
22 ms |
27996 KB |
Output is correct |
9 |
Correct |
10 ms |
17812 KB |
Output is correct |
10 |
Correct |
5 ms |
9308 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
47 ms |
48952 KB |
Output is correct |
13 |
Correct |
39 ms |
39508 KB |
Output is correct |
14 |
Correct |
26 ms |
29520 KB |
Output is correct |
15 |
Correct |
9 ms |
9564 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
62 ms |
49112 KB |
Output is correct |
18 |
Correct |
44 ms |
39760 KB |
Output is correct |
19 |
Correct |
17 ms |
20056 KB |
Output is correct |
20 |
Correct |
8 ms |
10584 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
48344 KB |
Output is correct |
2 |
Correct |
16 ms |
33752 KB |
Output is correct |
3 |
Correct |
13 ms |
25180 KB |
Output is correct |
4 |
Correct |
9 ms |
17500 KB |
Output is correct |
5 |
Correct |
5 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
39 ms |
49080 KB |
Output is correct |
8 |
Correct |
22 ms |
27996 KB |
Output is correct |
9 |
Correct |
10 ms |
17812 KB |
Output is correct |
10 |
Correct |
5 ms |
9308 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
47 ms |
48952 KB |
Output is correct |
13 |
Correct |
39 ms |
39508 KB |
Output is correct |
14 |
Correct |
26 ms |
29520 KB |
Output is correct |
15 |
Correct |
9 ms |
9564 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
62 ms |
49112 KB |
Output is correct |
18 |
Correct |
44 ms |
39760 KB |
Output is correct |
19 |
Correct |
17 ms |
20056 KB |
Output is correct |
20 |
Correct |
8 ms |
10584 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Runtime error |
488 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |