이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e9;
const int maxn=1e3;
const ll mod=998244353;
int a,b;
char g[maxn][maxn];
int used[maxn][maxn];
void clr(){
for(int i=1;i<=a;i++){
for(int t=1;t<=b;t++)used[i][t]=0;
}
}
void DFS(int x,int y,int ind){
if(g[x][y]=='x'){
cout<<":)"<<endl;
if(ind==2)cout<<'N';
else if(ind==1)cout<<'S';
else if(ind==3)cout<<'E';
else cout<<'W';
exit(0);
}
if(g[x][y]=='.' || used[x][y]==1){
return ;
}
used[x][y]=1;
if(g[x][y]=='v')DFS(x+1,y,ind);
if(g[x][y]=='^')DFS(x-1,y,ind);
if(g[x][y]=='>')DFS(x,y+1,ind);
if(g[x][y]=='<')DFS(x,y-1,ind);
}
void solve(){
cin>>a>>b;
pair <int,int> start,finish;
for(int i=1;i<=a;i++){
for(int t=1;t<=b;t++){
cin>>g[i][t];
if(g[i][t]=='o'){
start.first=i;
start.second=t;
}
if(g[i][t]=='x'){
finish.first=i;
finish.second=t;
}
}
}
DFS(start.first+1,start.second,1);
clr();
DFS(start.first-1,start.second,2);
clr();
DFS(start.first,start.second+1,3);
clr();
DFS(start.first,start.second-1,4);
cout<<":(";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
solve();
cout<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |