제출 #319508

#제출 시각아이디문제언어결과실행 시간메모리
319508gustasonPatkice (COCI20_patkice)C++14
30 / 50
1 ms512 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int dx[] = {0, 1, -1, 0}; int dy[] = {-1, 0, 0, 1}; map<int, char> mp = { {0,'W'}, {1,'S'}, {2,'N'}, {3,'E'} }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int best = 1e9 + 5, ans = -1; int n, m, startx, starty; cin >> n >> m; char mat[n][m]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> mat[i][j]; if (mat[i][j] == 'o') { startx = i; starty = j; } } } for(int i = 0; i < 4; i++) { int length = 0; int x = startx + dx[i], y = starty + dy[i]; bool reach = 0; while(1) { if (x < 0 || x >= n | y < 0 || y >= m) break; if (mat[x][y] == '.' || mat[x][y] == 'o') break; if (mat[x][y] == 'x') { reach = 1; break; } if (mat[x][y] == '<') { x += dx[0]; y += dy[0]; } else if (mat[x][y] == 'v') { x += dx[1]; y += dy[1]; } else if (mat[x][y] == '^') { x += dx[2]; y += dy[2]; } else if (mat[x][y] == '>') { x += dx[3]; y += dy[3]; } length++; } if (reach && length < best) { best = length; ans = i; } } if (ans != -1) { cout << ":)\n"; cout << mp[ans] << "\n"; } else { cout << ":("; } return 0; } //~ check for overflows

컴파일 시 표준 에러 (stderr) 메시지

patkice.cpp: In function 'int main()':
patkice.cpp:35:28: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   35 |             if (x < 0 || x >= n | y < 0 || y >= m) break;
      |                          ~~^~~~
patkice.cpp:32:13: warning: 'startx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |         int x = startx + dx[i], y = starty + dy[i];
      |             ^
patkice.cpp:32:33: warning: 'starty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |         int x = startx + dx[i], y = starty + dy[i];
      |                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...