Submission #445319

#TimeUsernameProblemLanguageResultExecution timeMemory
445319grtPatkice (COCI20_patkice)C++17
50 / 50
1 ms332 KiB
#include <bits/stdc++.h> #define ST first #define ND second #define PB push_back using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int INF = 1e9, nax = 110; int n, m; char t[nax][nax]; pi src, tar; int path(int x, int y) { int d = 1; while(1) { if(t[x][y] == '>') y++; else if(t[x][y] == '<') y--; else if(t[x][y] == '^') x--; else if(t[x][y] == 'v') x++; else if(t[x][y] == 'x') return d; else return INF; d++; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cin >> t[i][j]; if(t[i][j] == 'o') src = {i, j}; else if(t[i][j] == 'x') tar = {i, j}; } } pair<int, char>ans = {INF, 'A'}; if(src.ST > 0) ans = min(ans, {path(src.ST - 1, src.ND), 'N'}); if(src.ST < n) ans = min(ans, {path(src.ST + 1, src.ND), 'S'}); if(src.ND < m) ans = min(ans, {path(src.ST, src.ND + 1), 'E'}); if(src.ND > 0) ans = min(ans, {path(src.ST, src.ND - 1), 'W'}); if(ans.ND == 'A') cout << ":("; else cout << ":)\n" << ans.ND; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...