Submission #729229

#TimeUsernameProblemLanguageResultExecution timeMemory
729229nihaddhuseynliPatkice (COCI20_patkice)C++14
50 / 50
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; void solve(){ int n, m; cin >> n >> m; vector<vector<char>> a(n, vector<char>(m)); int sx, sy; for(int i=0; i<n; i++) for(int j=0; j<m; j++){ cin >> a[i][j]; if(a[i][j] == 'o') sx = i, sy = j; } char ans; int dist = INF; function<void(int, int, int, char)> dfs = [&](int x, int y, int d, char c){ if(a[x][y] == 'o' || a[x][y] == '.') return; if(a[x][y] == 'x'){ if(d < dist || (d == dist && c < ans)){ ans = c; dist = d; } } if(a[x][y] == '>') dfs(x, y+1, d+1, c); if(a[x][y] == '<') dfs(x, y-1, d+1, c); if(a[x][y] == 'v') dfs(x+1, y, d+1, c); if(a[x][y] == '^') dfs(x-1, y, d+1, c); }; dfs(sx-1, sy, 1, 'N'); dfs(sx, sy+1, 1, 'E'); dfs(sx+1, sy, 1, 'S'); dfs(sx, sy-1, 1, 'W'); if(dist == INF) cout << ":(\n"; else cout << ":)\n" << ans << "\n"; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); solve(); return 0; }

Compilation message (stderr)

patkice.cpp: In function 'void solve()':
patkice.cpp:37:8: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     dfs(sx, sy-1, 1, 'W');
      |     ~~~^~~~~~~~~~~~~~~~~~
patkice.cpp:11:9: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |     int sx, sy;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...