이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
بسم الله الرحمن الرحيم
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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |