Submission #470311

#TimeUsernameProblemLanguageResultExecution timeMemory
470311mychecksedadPatkice (COCI20_patkice)C++17
50 / 50
1 ms332 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back const int N = 110, F = 1e9+7; int n, m, sx, sy; char arr[N][N]; int dfs(int x, int y){ if(x == 0 || x == n + 1 || y == 0 || y == m + 1 || arr[x][y] == '.' || arr[x][y] == 'o') return F; if(arr[x][y] == 'x') return 1; int ans = 0; if(arr[x][y] == '>'){ ans = dfs(x, y + 1); } if(arr[x][y] == '<'){ ans = dfs(x, y - 1); } if(arr[x][y] == '^'){ ans = dfs(x - 1, y); } if(arr[x][y] == 'v'){ ans = dfs(x + 1, y); } return min(ans + 1, F); } int main(){ cin.tie(0); ios::sync_with_stdio(0); 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'){ sx = i, sy = j; } } } int ans1 = dfs(sx, sy + 1); int ans2 = dfs(sx, sy - 1); int ans3 = dfs(sx - 1, sy); int ans4 = dfs(sx + 1, sy); int r = min({ans1, ans2, ans3, ans4}); if(r==F){ cout << ":("; }else{ cout << ":)\n"; if(r == ans1) cout << "E"; else if(r == ans3) cout << "N"; else if(r == ans4) cout << "S"; else if(r == ans2) cout << "W"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...