Submission #741696

#TimeUsernameProblemLanguageResultExecution timeMemory
741696hfoliacotsPatkice (COCI20_patkice)C++17
30 / 50
1 ms596 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; vvi g; int dest = 0, o = 0; int rec(int n, int r) { if (n == dest) return r; for (int i: g[n]) return rec(i, r+1); return 1e9+1; } int main() { int r, s; cin >> r >> s; g = vvi(r*s, vi()); for (int i = 0; i < r*s; i++) { char c; cin >> c; if (c == '<') g[i].push_back(i-1); else if (c == '>') g[i].push_back(i+1); else if (c == '^') g[i].push_back(i-s); else if (c == 'v') g[i].push_back(i+s); else if (c == 'o') o = i; else if (c == 'x') dest = i; } int m = 1e9-1; string d = ":("; if (o % s != 0) { int a = rec(o-1, 0); if (a < m) { m = a; d = ":)\nW"; } } if (o % s != s-1) { int a = rec(o+1, 0); if (a < m) { m = a; d = ":)\nE"; } } if (o - s >= 0) { int a = rec(o-s, 0); if (a < m) { m = a; d = ":)\nN"; } } if (o + s < r*s) { int a = rec(o+s, 0); if (a < m) { m = a; d = ":)\nS"; } } cout << d << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...