Submission #495651

#TimeUsernameProblemLanguageResultExecution timeMemory
495651AlperenTPatkice (COCI20_patkice)C++17
50 / 50
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100 + 5, INF = 1e9 + 5; int n, m, ans = INF + 1, x, y, dist; char c = 'Z', arr[N][N]; int dfs(int x, int y){ if(arr[x][y] == 'x') return 0; else{ if(arr[x][y] == '^') return min(dfs(x - 1, y) + 1, INF); else if(arr[x][y] == '>') return min(dfs(x, y + 1) + 1, INF); else if(arr[x][y] == '<') return min(dfs(x, y - 1) + 1, INF); else if(arr[x][y] == 'v') return min(dfs(x + 1, y) + 1, INF); else return INF; } } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> arr[i][j]; if(arr[i][j] == 'o') x = i, y = j; } } if((dist = dfs(x - 1, y)) <= ans) c = (dist == ans ? min(c, 'N') : 'N'), ans = dist; if((dist = dfs(x, y + 1)) <= ans) c = (dist == ans ? min(c, 'E') : 'E'), ans = dist; if((dist = dfs(x, y - 1)) <= ans) c = (dist == ans ? min(c, 'W') : 'W'), ans = dist; if((dist = dfs(x + 1, y)) <= ans) c = (dist == ans ? min(c, 'S') : 'S'), ans = dist; if(ans == INF) cout << ":("; else cout << ":)\n" << c; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...