/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
using namespace std;
int r,c,m;
int const R=500+10;
int const M=5000+10;
vector<vector<char>>a(R,vector<char>(R));
string s;
int z=0;
vector<vector<vector<bool>>>vis(R,vector<vector<bool>>(R,vector<bool>(M)));
void dfs(int i,int j,int ind)
{
if (i<0||i>=r||j<0||j>=c||a[i][j]=='#')
return;
if (vis[i][j][ind])
return;
vis[i][j][ind]=1;
if (ind==m)
{
z++;
return;
}
if (s[ind]=='?')
{
dfs(i+1,j,ind+1);
dfs(i,j+1,ind+1);
dfs(i-1,j,ind+1);
dfs(i,j-1,ind+1);
}
if (s[ind]=='N')
dfs(i-1,j,ind+1);
if (s[ind]=='S')
dfs(i+1,j,ind+1);
if (s[ind]=='E')
dfs(i,j+1,ind+1);
if (s[ind]=='W')
dfs(i,j-1,ind+1);
}
inline void solve()
{
cin>>r>>c>>m;
for (int i=0;i<r;i++)
for (int j=0;j<c;j++)
cin>>a[i][j];
cin>>s;
for (int i=0;i<r;i++)
for (int j=0;j<c;j++)
dfs(i,j,0);
cout<<z<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
173904 KB |
Output is correct |
2 |
Correct |
155 ms |
173908 KB |
Output is correct |
3 |
Correct |
157 ms |
174004 KB |
Output is correct |
4 |
Correct |
160 ms |
173908 KB |
Output is correct |
5 |
Correct |
165 ms |
173892 KB |
Output is correct |
6 |
Correct |
155 ms |
173996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
173904 KB |
Output is correct |
2 |
Correct |
155 ms |
173908 KB |
Output is correct |
3 |
Correct |
157 ms |
174004 KB |
Output is correct |
4 |
Correct |
160 ms |
173908 KB |
Output is correct |
5 |
Correct |
165 ms |
173892 KB |
Output is correct |
6 |
Correct |
155 ms |
173996 KB |
Output is correct |
7 |
Correct |
170 ms |
173908 KB |
Output is correct |
8 |
Correct |
158 ms |
174040 KB |
Output is correct |
9 |
Correct |
156 ms |
173904 KB |
Output is correct |
10 |
Correct |
154 ms |
174116 KB |
Output is correct |
11 |
Correct |
154 ms |
174080 KB |
Output is correct |
12 |
Correct |
174 ms |
173924 KB |
Output is correct |
13 |
Correct |
179 ms |
174288 KB |
Output is correct |
14 |
Correct |
169 ms |
173956 KB |
Output is correct |
15 |
Correct |
158 ms |
174088 KB |
Output is correct |
16 |
Correct |
159 ms |
174160 KB |
Output is correct |
17 |
Correct |
178 ms |
174024 KB |
Output is correct |
18 |
Correct |
181 ms |
173984 KB |
Output is correct |
19 |
Correct |
167 ms |
174164 KB |
Output is correct |
20 |
Correct |
160 ms |
173896 KB |
Output is correct |
21 |
Correct |
156 ms |
174048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
173904 KB |
Output is correct |
2 |
Correct |
155 ms |
173908 KB |
Output is correct |
3 |
Correct |
157 ms |
174004 KB |
Output is correct |
4 |
Correct |
160 ms |
173908 KB |
Output is correct |
5 |
Correct |
165 ms |
173892 KB |
Output is correct |
6 |
Correct |
155 ms |
173996 KB |
Output is correct |
7 |
Correct |
170 ms |
173908 KB |
Output is correct |
8 |
Correct |
158 ms |
174040 KB |
Output is correct |
9 |
Correct |
156 ms |
173904 KB |
Output is correct |
10 |
Correct |
154 ms |
174116 KB |
Output is correct |
11 |
Correct |
154 ms |
174080 KB |
Output is correct |
12 |
Correct |
174 ms |
173924 KB |
Output is correct |
13 |
Correct |
179 ms |
174288 KB |
Output is correct |
14 |
Correct |
169 ms |
173956 KB |
Output is correct |
15 |
Correct |
158 ms |
174088 KB |
Output is correct |
16 |
Correct |
159 ms |
174160 KB |
Output is correct |
17 |
Correct |
178 ms |
174024 KB |
Output is correct |
18 |
Correct |
181 ms |
173984 KB |
Output is correct |
19 |
Correct |
167 ms |
174164 KB |
Output is correct |
20 |
Correct |
160 ms |
173896 KB |
Output is correct |
21 |
Correct |
156 ms |
174048 KB |
Output is correct |
22 |
Execution timed out |
1084 ms |
174568 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |