# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486308 | Christopher_ | Patkice (COCI20_patkice) | C++17 | 1 ms | 204 KiB |
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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m;
cin >> n >> m;
vector<string> g(n);
pair<int, int> st, fi;
vector<vector<bool>> vis(n, vector<bool>(m));
for (int i = 0; i < n; ++i) {
cin >> g[i];
for (int j = 0; j < m; ++j) {
if (g[i][j] == 'o') {
st = {i, j};
} else if (g[i][j] == 'x') {
fi = {i, j};
}
}
}
auto e = [&](int x, int y) {
if (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] && g[x][y] != '.') return true;
return false;
};
int x, y;
x = st.first, y = st.second;
x++;
while (x != fi.first || y != fi.second) {
if (!e(x, y)) {
break;
}
vis[x][y] = true;
if (g[x][y] == '^') {
x--;
} else if (g[x][y] == 'v') {
x++;
} else if (g[x][y] == '>') {
y++;
} else {
--y;
}
}
if (x == fi.first && y == fi.second) {
return cout << ":)" << '\n' << "S" << '\n', 0;
}
x = st.first, y = st.second;
x--;
while (x != fi.first || y != fi.second) {
if (!e(x, y)) {
break;
}
vis[x][y] = true;
if (g[x][y] == '^') {
x--;
} else if (g[x][y] == 'v') {
x++;
} else if (g[x][y] == '>') {
y++;
} else {
--y;
}
}
if (x == fi.first && y == fi.second) {
return cout << ":)" << '\n' << "N" << '\n', 0;
}
x = st.first, y = st.second;
y++;
while (x != fi.first || y != fi.second) {
if (!e(x, y)) {
break;
}
vis[x][y] = true;
if (g[x][y] == '^') {
x--;
} else if (g[x][y] == 'v') {
x++;
} else if (g[x][y] == '>') {
y++;
} else {
--y;
}
}
if (x == fi.first && y == fi.second) {
return cout << ":)" << '\n' << "R" << '\n', 0;
}
x = st.first, y = st.second;
y--;
while (x != fi.first || y != fi.second) {
if (!e(x, y)) {
break;
}
vis[x][y] = true;
if (g[x][y] == '^') {
x--;
} else if (g[x][y] == 'v') {
x++;
} else if (g[x][y] == '>') {
y++;
} else {
--y;
}
}
if (x == fi.first && y == fi.second) {
return cout << ":)" << '\n' << "L" << '\n', 0;
}
cout << ":(" << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |