#include"iostream"
// #include"vector"
// #include"queue"
// #include"deque"
// #include"set"
// #include"map"
// #include"algorithm"
// #include"iomanip"
// #include"cstring"
// #define int long long
using namespace std;
const int maxn=105;
const int INF = 1e9;
pair<int,int> duck;
char g[maxn][maxn];
int len=0;
void dfs(int x,int y){
if(g[x][y]=='.' || g[x][y]=='o'){len=INF; return;}
if(g[x][y]=='>'){
len++;
dfs(x,y+1);
}
if(g[x][y]=='<'){
len++;
dfs(x,y-1);
}
if(g[x][y]=='^'){
len++;
dfs(x-1,y);
}
if(g[x][y]=='v'){
len++;
dfs(x+1,y);
}
if(g[x][y]=='x') return;
}
void solve(){
int n,m;
cin >> n >> m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin >> g[i][j];
if(g[i][j]=='o'){
duck = {i,j};
}
}
}
int a,b,c,d;
// cout << duck.first << "*" << duck.second << "\n";
dfs(duck.first,duck.second+1);
a = len;
len=0;
dfs(duck.first,duck.second-1);
b = len;
len=0;
dfs(duck.first+1,duck.second);
c = len;
len=0;
dfs(duck.first-1,duck.second);
d = len;
// cout << a << " " << b << " " << c << " " << d << "\n\n";
int mini = min(a,min(b,min(c,d)));
if(mini==INF){cout << ":(";}
else{
cout << ":)\n";
if(a==mini){cout << "E";}
else if(b==mini){cout << "W";}
else if(c==mini){cout << "S";}
else if(d==mini){cout << "N";}
}
}
signed main(){
// ios::sync_with_stdio(false); cin.tie(0);
// freopen("","r",stdin);freopen("","w",stdout);
int t=1;
// cin >> t;
for(int i=1;i<=t;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
292 KB |
Output is correct |
17 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |