Submission #494898

#TimeUsernameProblemLanguageResultExecution timeMemory
494898kappaPatkice (COCI20_patkice)C++14
30 / 50
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; int r, s, col, row, mark[105][105]; pair<int, int> dir[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; pair<char, int> cevap; char d[105][105]; pair<bool, int> check(int x, int y, int step){ if(mark[x][y]){ return {false, 0}; } mark[x][y] = 1; char ch = d[x][y]; pair<bool, int> ans; switch (ch) { case 'x': return {true, step}; break; case '>': ans = check(x, y + 1, step + 1); break; case '<': ans = check(x, y - 1, step + 1); break; case 'v': ans = check(x + 1, y, step + 1); break; case '^': ans = check(x - 1, y, step + 1); break; default: return {false, 0}; break; } return ans; } int main(){ cevap.second = INT_MAX; cin >> r >> s; for (int i = 0; i < r; i++) { for (int j = 0; j < s; j++) { cin >> d[i][j]; if(d[i][j] == 'o'){ row = i; col = j; } } } for (int i = 0; i < 4; i++) { pair<bool, int> temp = check(row + dir[i].first, col + dir[i].second, 1); if(temp.first && temp.second < cevap.second){ cevap.second = temp.second; switch (i) { case 0: cevap.first = 'S'; break; case 1: cevap.first = 'N'; break; case 2: cevap.first = 'E'; break; default: cevap.first = 'W'; break; } } memset(mark, 0, sizeof(mark)); } if(cevap.first){ cout << ":)\n" << cevap.first; }else{ cout << ":("; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...