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 <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int r, c;
cin >> r >> c;
vector<vector<char>> m(r, vector<char>(c));
string s;
int x0 = 0, y0 = 0;
for (int i = 0; i < r; i++) {
cin >> s;
for (int j = 0; j < c; j++) {
m[i][j] = s[j];
if (s[j] == 'o') {
x0 = i;
y0 = j;
}
}
}
map<char, pair<int, int>> dir;
dir['>'] = {0, 1};
dir['<'] = {0, -1};
dir['v'] = {1, 0};
dir['^'] = {-1, 0};
// Order: E, N, S, W
vector<pair<int, int>> st;
st.push_back({0, 1});
st.push_back({-1, 0});
st.push_back({1, 0});
st.push_back({0, -1});
int x, y, cnt, idx = -1, mn = 1e9;
for (int i = 0; i < 4; i++) {
x = x0 + st[i].first;
y = y0 + st[i].second;
cnt = 0;
while (true) {
if (m[x][y] == '.' || m[x][y] == 'o') {
break;
} else if (m[x][y] == 'x') {
if (cnt < mn) {
mn = cnt;
idx = i;
}
break;
}
char d = m[x][y];
x += dir[d].first;
y += dir[d].second;
cnt++;
}
}
vector<char> let = {'E', 'N', 'S', 'W'};
if (idx != -1) {
cout << ":)\n";
cout << let[idx] << '\n';
} else {
cout << ":(\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |