Submission #377622

#TimeUsernameProblemLanguageResultExecution timeMemory
377622dimashiiPatkice (COCI20_patkice)C++17
50 / 50
1 ms1516 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int mxN = 5e3 + 5, mod = 1e9 + 7; char a[mxN][mxN], d[mxN][mxN]; bool used[mxN][mxN]; int r, s; int main() { ios :: sync_with_stdio(false), cin.tie(nullptr); cin >> r >> s; for (int i = 1; i <= r; ++i) { for (int j = 1; j <= s; ++j) { cin >> a[i][j]; d[i][j] = '#'; } } queue <pair <int, int> > q; for (int i = 1; i <= r; ++i) { for (int j = 1; j <= s; ++j) { if (a[i][j] == 'o') { used[i][j] = 1; q.push({i, j}); break; } } } while (!q.empty()) { int i = q.front().first; int j = q.front().second; q.pop(); if (a[i][j] == 'x') { cout << ":)\n" << d[i][j]; return 0; } if (a[i][j] == 'o') { if (j + 1 <= s) { used[i][j + 1] = 1; q.push({i, j + 1}); d[i][j + 1] = 'E'; } if (i - 1 > 0) { used[i - 1][j] = 1; q.push({i - 1, j}); d[i - 1][j] = 'N'; } if (i + 1 <= r) { used[i + 1][j] = 1; q.push({i + 1, j}); d[i + 1][j] = 'S'; } if (j - 1 > 0) { used[i][j - 1] = 1; q.push({i, j - 1}); d[i][j - 1] = 'W'; } } else if (a[i][j] != '.') { if (a[i][j] == 'v' && !used[i + 1][j]) { used[i + 1][j] = 1; q.push({i + 1, j}); d[i + 1][j] = d[i][j]; } if (a[i][j] == '^' && !used[i - 1][j]) { used[i - 1][j] = 1; q.push({i - 1, j}); d[i - 1][j] = d[i][j]; } if (a[i][j] == '>' && !used[i][j + 1]) { used[i][j + 1] = 1; q.push({i, j + 1}); d[i][j + 1] = d[i][j]; } if (a[i][j] == '<' && !used[i][j - 1]) { used[i][j - 1] = 1; q.push({i, j - 1}); d[i][j - 1] = d[i][j]; } } } cout << ":("; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...