이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=105;
char a[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
string s;cin>>s;
set <pair <int,int> > st;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]=='#')continue;
queue <vector <int> > q;
q.push({i,j,-1});
while(!q.empty()){
int x=q.front()[0];
int y=q.front()[1];
int ind=q.front()[2];
q.pop();
ind++;
if(ind==k){
st.insert({x,y});
continue;
}
if(s[ind]=='W' && y-1>=0 && a[x][y-1]=='.')q.push({x,y-1,ind});
if(s[ind]=='E' && y+1<m && a[x][y+1]=='.')q.push({x,y+1,ind});
if(s[ind]=='S' && x+1<n && a[x+1][y]=='.')q.push({x+1,y,ind});
if(s[ind]=='N' && x-1>=0 && a[x-1][y]=='.')q.push({x-1,y,ind});
if(s[ind]=='?'){
if(y-1>=0 && a[x][y-1]=='.')q.push({x,y-1,ind});
if(y+1<m && a[x][y+1]=='.')q.push({x,y+1,ind});
if(x-1>=0 && a[x-1][y]=='.')q.push({x-1,y,ind});
if(x+1<n && a[x+1][y]=='.')q.push({x+1,y,ind});
}
}
}
}
cout<<st.size()<<"\n";
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |