Submission #741690

#TimeUsernameProblemLanguageResultExecution timeMemory
741690a_aguiloPatkice (COCI20_patkice)C++14
0 / 50
1076 ms212 KiB
#include<bits/stdc++.h> using namespace std; int r, s; vector<vector<int>> distance; vector<string> sea; int dfs(int x, int y){ if(x >= r or y >= s) return 1e9; if(x < 0 or y < 0) return 1e9; if(sea[x][y] == '.') return 1e9; if(sea[x][y] == '^') return 1+dfs(x-1, y); if(sea[x][y] == 'x') return 0; if(sea[x][y] == '<') return 1+dfs(x, y-1); if(sea[x][y] == '>') return 1+dfs(x, y+1); if(sea[x][y] == 'v') return 1+dfs(x+1, y); } int main(){ cin >> r >> s; pair<int, int> start; sea = vector<string>(r); for(int i = 0; i < r; ++i) { cin >> sea[i]; for(int j = 0; j < s; ++j){ if(sea[i][j] == 'o') start = {i, j}; } } int bestDistance = 1e9; char directionBest = '-'; int east = dfs(start.first, start.second+1); if(east < bestDistance){ bestDistance = east; directionBest = 'E'; } int north = dfs(start.first-1, start.second); if(north < bestDistance){ bestDistance = north; directionBest = 'N'; } int south = dfs(start.first +1, start.second); if(south < bestDistance){ bestDistance = south; directionBest = 'S'; } int west = dfs(start.first, start.second-1); if(west < bestDistance){ bestDistance = west; directionBest = 'W'; } if(bestDistance == 1e9) cout << ":(" << endl; else{ cout << ":)" << endl; cout << directionBest << endl; } return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int dfs(int, int)':
patkice.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...