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 pii pair<int, int>
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;
vector<string> a;
const ll MAX = 2147483647;
int calc(int x, int y){
int ans = 0;
while(true){
if(a[x][y] == '<') y--;
else if(a[x][y] == '>') y++;
else if(a[x][y] == '^') x--;
else if(a[x][y] == 'v') x++;
else break;
ans++;
}
if(a[x][y] == 'x') return ans + 1;
else return MAX;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
a.resize(n);
pii o;
for(int i = 0; i < n; i++){
cin >> a[i];
for(int j = 0; j < m; j++){
if(a[i][j] == 'o') o = mp(i, j);
}
}
vector<pii> dir = {mp(0, 1), mp(-1, 0), mp(1, 0), mp(0, -1)};
vector<char> c = {'E', 'N', 'S', 'W'};
int ans = MAX;
char ansp = '.';
for(int i = 0; i < 4; i++){
int tmp = calc(o.F + dir[i].F, o.S + dir[i].S);
if(tmp < ans){
ans = tmp;
ansp = c[i];
}
}
if(ans == MAX){
cout << ":(\n";
return 0;
}
cout << ":)\n";
cout << ansp << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |