제출 #1166907

#제출 시각아이디문제언어결과실행 시간메모리
1166907achiPatkice (COCI20_patkice)C++17
50 / 50
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; pair<int, int> getPos (char direct, pair<int, int> pos) { if (direct == 'N' || direct == '^') return {pos.first-1, pos.second}; if (direct == 'S' || direct == 'v') return {pos.first+1, pos.second}; if (direct == 'E' || direct == '>') return {pos.first, pos.second+1}; return {pos.first, pos.second-1}; } int main () { cin.tie(0)->sync_with_stdio(0); int r, s; cin >> r >> s; char c; pair<int, int> init_pos; vector<vector<char>> grid(r, vector<char>(s)); for (int i = 0; i < r; i++) { for (int j = 0; j < s; j++) { cin >> c; grid[i][j] = c; if (c == 'o') init_pos = {i, j}; } } vector<pair<int, char>> valid; vector<char> direction = {'N', 'E', 'S', 'W'}; int dist = 0; for (int i = 0; i < 4; i++) { pair<int, int> pos = getPos(direction[i], init_pos); dist = 0; while (grid[pos.first][pos.second] != '.') { if (grid[pos.first][pos.second] == 'x') { valid.push_back({dist, direction[i]}); break; } pos = getPos(grid[pos.first][pos.second], pos); dist++; if (grid[pos.first][pos.second] == 'o') { break; } } } if (valid.empty()) { cout << ":("; return 0; } sort(valid.begin(), valid.end()); cout << ":)\n" << valid.front().second; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...