#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=105;
int const inf=1e9+7;
int n,m,sx,sy,ex,ey;
int a[4]={0,1,0,-1};
int b[4]={1,0,-1,0};
string di="ESWN";
char s[N][N];
int dfs(int x,int y,int d=1){
if (x < 1 or y < 1 or x > n or y > m)
return inf;
if (s[x][y] == 'x')
return d;
if (s[x][y] == '.' or s[x][y] == 'o')
return inf;
if (s[x][y] == '>')
return dfs(x, y + 1, d + 1);
if (s[x][y] == '<')
return dfs(x, y - 1, d + 1);
if (s[x][y] == 'v')
return dfs(x + 1, y, d + 1);
if (s[x][y] == '^')
return dfs(x - 1, y, d + 1);
return 0;
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= m; j ++){
cin >> s[i][j];
if (s[i][j] == 'x')
ex = i, ey = j;
else if (s[i][j] == 'o')
sx = i, sy = j;
}
}
pair<int,char> p={inf,'a'};
for(int i=0;i<4;i++)
p=min(p,{dfs(sx+a[i],sy+b[i]),di[i]});
if(p.first==inf){
cout<<":("<<endl;
return 0;
}
cout<<":)"<<endl;
cout<<p.second<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
440 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |