Submission #321730

#TimeUsernameProblemLanguageResultExecution timeMemory
321730alextodoranPatkice (COCI20_patkice)C++17
50 / 50
1 ms492 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int NM_MAX = 102; int n, m; char ma[NM_MAX][NM_MAX]; struct Cell { int a, b; }; bool inside (Cell c) { return 1 <= c.a & c.a <= n && 1 <= c.b && c.b <= m; } char dir[] = {'N', 'E', 'S', 'W'}; int da[] = {-1, 0, 1, 0}, db[] = {0, 1, 0, -1}; int f (char c) { if(c == '^') return 0; else if(c == '>') return 1; else if(c == 'v') return 2; else if(c == '<') return 3; return -1; } Cell start, finish; int dfs (Cell c) { if(ma[c.a][c.b] == 'x') return 0; if(f(ma[c.a][c.b]) == -1) return -1; int d = f(ma[c.a][c.b]); Cell c1 = Cell{c.a + da[d], c.b + db[d]}; int len = dfs(c1); if(len == -1) return -1; return len + 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> ma[i][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(ma[i][j] == 'o') start = Cell{i, j}; else if(ma[i][j] == 'x') finish = Cell{i, j}; int minLen = INT_MAX; char ans = 'X'; for(int d = 0; d < 4; d++) { Cell c = Cell{start.a + da[d], start.b + db[d]}; if(inside(c) == false) continue; int len = dfs(c); if(len == -1) continue; if(len < minLen || (len == minLen && dir[d] < ans)) { minLen = len; ans = dir[d]; } } if(ans == 'X') cout << ":(\n"; else cout << ":)\n" << ans << "\n"; return 0; }

Compilation message (stderr)

patkice.cpp: In function 'bool inside(Cell)':
patkice.cpp:28:14: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   28 |     return 1 <= c.a & c.a <= n && 1 <= c.b && c.b <= m;
      |            ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...