/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
int r,c,m;
int const R=500+10;
int const M=5000+10;
char a[R][R]={};
string s;
int ans=0;
bitset<M>vis[R][R]={};
queue<pair<int,pair<int,int>>>Q;
inline bool check(int i,int j,int ind)
{
if (i<0||i>=r||j<0||j>=c||a[i][j]=='#'||vis[i][j][ind])
return 0;
Q.push({ind,{i,j}});
vis[i][j][ind]=1;
return 1;
}
inline void bfs(int i,int j)
{
check(i,j,0);
while (Q.size())
{
auto z=Q.front();
Q.pop();
int ind=z.first,i=z.second.first,j=z.second.second;
if (ind==m)
{
ans++;
return;
}
if (s[ind]=='?')
{
check(i+1,j,ind+1);
check(i,j+1,ind+1);
check(i-1,j,ind+1);
check(i,j-1,ind+1);
}
if (s[ind]=='N')
check(i-1,j,ind+1);
if (s[ind]=='S')
check(i+1,j,ind+1);
if (s[ind]=='E')
check(i,j+1,ind+1);
if (s[ind]=='W')
check(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++)
bfs(i,j);
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
14 ms |
7004 KB |
Output is correct |
8 |
Correct |
6 ms |
6780 KB |
Output is correct |
9 |
Correct |
4 ms |
6492 KB |
Output is correct |
10 |
Correct |
4 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
7000 KB |
Output is correct |
13 |
Correct |
24 ms |
7004 KB |
Output is correct |
14 |
Correct |
18 ms |
6956 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
19 ms |
7096 KB |
Output is correct |
18 |
Correct |
29 ms |
7104 KB |
Output is correct |
19 |
Correct |
9 ms |
6492 KB |
Output is correct |
20 |
Correct |
6 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
14 ms |
7004 KB |
Output is correct |
8 |
Correct |
6 ms |
6780 KB |
Output is correct |
9 |
Correct |
4 ms |
6492 KB |
Output is correct |
10 |
Correct |
4 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
7000 KB |
Output is correct |
13 |
Correct |
24 ms |
7004 KB |
Output is correct |
14 |
Correct |
18 ms |
6956 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
19 ms |
7096 KB |
Output is correct |
18 |
Correct |
29 ms |
7104 KB |
Output is correct |
19 |
Correct |
9 ms |
6492 KB |
Output is correct |
20 |
Correct |
6 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
1073 ms |
72216 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |