Submission #398904

#TimeUsernameProblemLanguageResultExecution timeMemory
398904retsigerPatkice (COCI20_patkice)C++14
50 / 50
1 ms332 KiB
#include<bits/stdc++.h> #define x first #define y second #define bug(x) cerr<<#x<<" = "<<x<<'\n' using namespace std; typedef pair <int, int> ii; const int maxn = 105; int N, M; char A[maxn][maxn]; int dfs(int u, int v) { if (A[u][v] == 'o' || A[u][v] == '.') return -1; if (A[u][v] == 'x') return 1; int nu = u, nv = v; if (A[u][v] == '<') --nv; else if (A[u][v] == '>') ++nv; else if (A[u][v] == 'v') ++nu; else --nu; int k = dfs(nu, nv); if (k == -1) return -1; return 1 + k; } int main() { ios::sync_with_stdio(0); cin.tie(0); // freopen("cc.inp", "r", stdin); // freopen("cc.out", "w", stdout); cin >> N >> M; int stx, sty; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { cin >> A[i][j]; if (A[i][j] == 'o') { stx = i; sty = j; } } } int mn = (int)1e9; char ans = 'Z'; int k = dfs(stx - 1, sty); if (k != -1) { if (k < mn) { mn = k; ans = 'N'; } } k = dfs(stx + 1, sty); if (k != -1) { if (k < mn) { mn = k; ans = 'S'; } else if (k == mn) { ans = min(ans, 'S'); } } k = dfs(stx, sty - 1); if (k != -1) { if (k < mn) { mn = k; ans ='W'; } else if (k == mn) { ans = min(ans, 'W'); } } k = dfs(stx, sty + 1); if (k != -1) { if (k < mn) { mn = k; ans ='E'; } else if (k == mn) { ans = min(ans, 'E'); } } if (ans == 'Z') { cout << ":("; } else cout << ":)\n" << ans << '\n'; return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:52:10: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |   k = dfs(stx + 1, sty);
      |       ~~~^~~~~~~~~~~~~~
patkice.cpp:52:10: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...