Submission #486320

#TimeUsernameProblemLanguageResultExecution timeMemory
486320Christopher_Patkice (COCI20_patkice)C++17
30 / 50
1 ms332 KiB
#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}; } } } struct node { int d, x, y, ty; bool operator <(const node& o) const { return d > o.d; } }; 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; }; auto pr = [](int k) { if (k == 0) { return 'E'; } else if (k == 1) { return 'S'; } else if (k == 2) { return 'W'; } else { return 'N'; } }; queue<node> q; q.push({0, st.first, st.second, -1}); while (!q.empty()) { int d = q.front().d, x = q.front().x, y = q.front().y, ty = q.front().ty; q.pop(); if (vis[x][y]) { continue; } vis[x][y] = true; if (x == fi.first && y == fi.second) { cout << ":)" << '\n' << pr(ty) << '\n'; return 0; } else if (x == st.first && y == st.second) { for (int k = 0; k < 4; ++k) { int nx = x + dx[k], ny = y + dy[k]; if (e(nx, ny)) { if (x == st.first && y == st.second) { q.push({d + 1, nx, ny, k}); } else { q.push({d + 1, nx, ny, ty}); } } } } else { if (g[x][y] == '^') { q.push({d + 1, x - 1, y, ty}); } else if (g[x][y] == 'v') { q.push({d + 1, x + 1, y, ty}); } else if (g[x][y] == '>') { q.push({d + 1, x, y + 1, ty}); } else if (g[x][y] == '<') { q.push({d + 1, x, y - 1, ty}); } } } cout << ":(" << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...