#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ft first
#define sd second
ll n, m;
char ch[105][105];
pair<ll, ll>s;
const int dirx[4] = {0, 1, 0, -1};
const int diry[4] = {1, 0, -1, 0};
int dfs(int x, int y, int res = 1){
if(ch[x][y] == '.' || ch[x][y] == 'o')return 2e9;
if(ch[x][y] == 'x')return res;
if(ch[x][y] == '^')return dfs(x - 1, y, res + 1);
if(ch[x][y] == 'v')return dfs(x + 1, y, res + 1);
if(ch[x][y] == '>')return dfs(x, y + 1, res + 1);
if(ch[x][y] == '<')return dfs(x, y - 1, res + 1);
return 2e9;
}
void fun(){
cin>>n>>m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin>>ch[i][j];
if(ch[i][j] == 'o')
s = {i, j};
}
}
int cur, mn = 2e9;
char ans = '!';
for(int i = 0; i < 4; i++){
cur = dfs(s.ft + dirx[i], s.sd + diry[i]);
if(cur < mn){
mn = cur;
if(i == 0)
ans = 'E';
else if(i == 1)
ans = 'S';
else if(i == 2)
ans = 'W';
else
ans = 'N';
}
}
if(ans == '!')
cout<<":(";
else
cout<<":)\n"<<ans;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int ttt = 1;
//cin>>ttt;
while(ttt--)fun();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |