This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
//#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 2e5+1;
void solve() {
int n,m;
cin >> n >> m;
char grid[n+1][m+1];
int px,py;
F(i,n) {
string s;
cin >> s;
F(j,m) {
grid[i][j] = s[j-1];
if (grid[i][j] == 'o') px = i,py = j;
}
}
vector<char> dirs = {'E','W','N','S'};
vi dx = {0,0,-1,1};
vi dy = {1,-1,0,0};
int steps = 1e9;
string ans;
char ans2;
for (int i=0;i<4;i++) {
int x = px+dx[i];
int y = py+dy[i];
if (!(x <= n && x >= 1 && y <=m && y >= 1)) continue;
int haha = 0;
while (grid[x][y] != '.') {
haha++;
if (grid[x][y] == '>') y++;
else if (grid[x][y] == '<') y--;
else if (grid[x][y] == '^') x--;
else if (grid[x][y] == 'v') x++;
else break;
}
if (grid[x][y] == 'x') {
if (haha < steps){
steps = haha;
ans = ":)\n";
ans2 = dirs[i];
}
}
}
if (ans[1] == ')') cout << ans << ans2 << endl;
else cout << ":(\n";
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message (stderr)
patkice.cpp: In function 'void solve()':
patkice.cpp:30:7: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
30 | char ans2;
| ^~~~
patkice.cpp:32:18: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
32 | int x = px+dx[i];
| ^
patkice.cpp:33:18: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
33 | int y = py+dy[i];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |