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>
#define _USE_MATH_DEFINES
#define endl "\n"
#define sp " "
#define MOD 1000000007
#define f1(i, x) for(auto &i : x)
#define f2(i, x) for(ll i = 0; i < x; i++)
#define raya() cout << endl << "====================================" << endl
using namespace std;
typedef long long ll;
vector<vector<char>> arr;
ll n, m;
ll no = 0, e = 0, w = 0, s = 0;
void fun(ll &dir, ll o, ll j){
if(o < 0 or j < 0){
dir = -1;
return;
}
if(o == n or j == m){
dir = -1;
return;
}
char i = arr[o][j];
if(i == '.' or i == 'o'){
dir = -1;
return;
}
dir++;
if(i == 'x')
return;
if(i == 'v') fun(dir, o + 1, j);
if(i == '^') fun(dir, o - 1, j);
if(i == '>') fun(dir, o, j + 1);
if(i == '<') fun(dir, o, j - 1);
}
void solve(){
cin >> n >> m;
ll xi, xj;
arr.resize(n, vector<char>(m));
f2(i, n){
f2(j, m){
cin >> arr[i][j];
if(arr[i][j] == 'o'){
xi = i;
xj = j;
}
}
}
fun(no, xi - 1, xj);
fun(e, xi, xj + 1);
fun(w, xi, xj - 1);
fun(s, xi + 1, xj);
vector<pair<ll, char>> ans;
if(no != -1) ans.push_back({no, 'N'});
if(e != -1) ans.push_back({e, 'E'});
if(w != -1) ans.push_back({w, 'W'});
if(s != -1) ans.push_back({s, 'S'});
if(ans.size()){
sort(ans.begin(), ans.end());
cout << ":)" << endl;
cout << ans[0].second;
} else cout << ":(";
}
int main(){
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
solve();
}
Compilation message (stderr)
patkice.cpp: In function 'void solve()':
patkice.cpp:51:8: warning: 'xj' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | fun(w, xi, xj - 1);
| ~~~^~~~~~~~~~~~~~~
patkice.cpp:52:8: warning: 'xi' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | fun(s, xi + 1, xj);
| ~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |