Submission #934109

#TimeUsernameProblemLanguageResultExecution timeMemory
934109pakapuPatkice (COCI20_patkice)C++17
50 / 50
1 ms504 KiB
#include <bits/stdc++.h> using namespace std; int can_get_home(int i, int j, int curr_moves, vector<string> &land) { if (i >= land.size() || j >= land[0].size() || i < 0 || j < 0) { return 1e9 + 1; } switch (land[i][j]) { case '>': return can_get_home(i, j + 1, curr_moves + 1, land); break; case '<': return can_get_home(i, j - 1, curr_moves + 1, land); break; case '^': return can_get_home(i - 1, j, curr_moves + 1, land); break; case 'v': return can_get_home(i + 1, j, curr_moves + 1, land); break; case 'x': return curr_moves; default: return 1e9 + 1; } } int main() { int n, m; cin >> n >> m; vector<string> land(n); int start_i = -1; int start_j = -1; for (int i = 0; i < n; i++) { cin >> land[i]; for (int j = 0; j < land[i].size(); j++) { if (land[i][j] == 'o') { start_i = i; start_j = j; } } } assert(start_i != -1); assert(start_j != -1); int min_moves = 1e9 + 1; int curr_moves = -1; char min_dir = '!'; curr_moves = can_get_home(start_i, start_j + 1, 0, land); if (curr_moves < min_moves) { min_moves = curr_moves; min_dir = 'E'; } curr_moves = can_get_home(start_i - 1, start_j, 0, land); if (curr_moves < min_moves) { min_moves = curr_moves; min_dir = 'N'; } curr_moves = can_get_home(start_i + 1, start_j, 0, land); if (curr_moves < min_moves) { min_moves = curr_moves; min_dir = 'S'; } curr_moves = can_get_home(start_i, start_j - 1, 0, land); if (curr_moves < min_moves) { min_moves = curr_moves; min_dir = 'W'; } if (min_moves == 1e9 + 1) { cout << ":(\n"; } else { cout << ":)\n"; cout << min_dir << '\n'; } return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int can_get_home(int, int, int, std::vector<std::__cxx11::basic_string<char> >&)':
patkice.cpp:7:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  if (i >= land.size()
      |      ~~^~~~~~~~~~~~~~
patkice.cpp:8:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   || j >= land[0].size()
      |      ~~^~~~~~~~~~~~~~~~~
patkice.cpp: In function 'int main()':
patkice.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j = 0; j < land[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...