#include <bits/stdc++.h>
#define int long long
typedef unsigned long long ull;
using namespace std;
const int N=105;
int n,m,mvx[]={0,-1,1,0},mvy[]={1,0,0,-1};
char a[N][N];
int dfs(int x,int y){
if (a[x][y]=='x') return 1;
if (a[x][y]=='.' || a[x][y]=='o') return INT_MIN;
if (a[x][y]=='^') return dfs(x-1,y)+1;
if (a[x][y]=='v') return dfs(x+1,y)+1;
if (a[x][y]=='>') return dfs(x,y+1)+1;
if (a[x][y]=='<') return dfs(x,y-1)+1;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
bool ok=false;
char c='h';
int mn=INT_MAX;
cin>>n>>m;
int x=0,y=0;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
cin>>a[i][j];
if (a[i][j]=='o'){
x=i;
y=j;
}
}
}
for (int i=0;i<4;i++){
int d=dfs(x+mvx[i],y+mvy[i]);
if (d<0) continue;
ok=true;
if (d<mn){
mn=d;
if (i==0) c='E';
if (i==1) c='N';
if (i==2) c='S';
if (i==3) c='W';
}
}
if (ok) cout<<":)"<<endl<<c<<endl;
else cout<<":("<<endl;
return 0;
}
Compilation message
patkice.cpp: In function 'long long int dfs(long long int, long long int)':
patkice.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
16 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |