#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<string>v;
bool valid(int x, int y) {
if(x < 0 || x >= n || y < 0 || y >= m || v[x][y] == '.' || v[x][y] == 'x') return false;
return true;
}
signed main() {
cin>>n>>m;
v.resize(n);
for(auto &z : v) cin>>z;
pair<int,int>s,e;
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < m ; j++) {
if(v[i][j] == 'o') s.first=i,s.second=j;
if(v[i][j] == 'x') e.first=i,e.second=j;
}
}
char winner;
bool f = false;
int cnt, best=INT_MAX;
int x,y;
char c;
x = s.first, y = s.second+1;
c = 'E';
cnt=0;
while(valid(x,y)) {
if(v[x][y] == '<') y--;
else if(v[x][y] == '^') x--;
else if (v[x][y] == '>') y++;
else x++;
cnt++;
}
if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
if(cnt < best) best=cnt,winner=c,f=true;
}
cnt=0;
x = s.first-1, y = s.second;
c = 'N';
while(valid(x,y)) {
if(v[x][y] == '<') y--;
else if(v[x][y] == '^') x--;
else if (v[x][y] == '>') y++;
else x++;
cnt++;
}
if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
if(cnt < best) best=cnt,winner=c,f=true;
}
x = s.first+1, y = s.second;
c = 'S';
cnt=0;
while(valid(x,y)) {
if(v[x][y] == '<') y--;
else if(v[x][y] == '^') x--;
else if (v[x][y] == '>') y++;
else x++;
cnt++;
}
if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
if(cnt < best) best=cnt,winner=c,f=true;
}
x = s.first, y = s.second-1;
c = 'W';
cnt=0;
while(valid(x,y)) {
if(v[x][y] == '<') y--;
else if(v[x][y] == '^') x--;
else if (v[x][y] == '>') y++;
else x++;
cnt++;
}
if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
if(cnt < best) best=cnt,winner=c,f=true;
}
if(!f) cout << ":(";
else cout << ":)\n" << winner;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |