# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
698478 | 2023-02-13T15:24:59 Z | Do_you_copy | Papričice (COCI20_papricice) | C++14 | 2 ms | 4180 KB |
#include <bits/stdc++.h> #define fi first #define se second #define faster ios_base::sync_with_stdio(0); cin.tie(0); #define pb push_back using namespace std; using ll = long long; using pii = pair <int, int>; const int maxN = 1000 + 1; const int inf = 0x3f3f3f3f; int n, m; string S[maxN]; char trace[maxN][maxN]; int d[maxN][maxN]; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; char c(int i){ if (i == 0) return 'E'; if (i == 1) return 'W'; if (i == 2) return 'N'; if (i == 3) return 'S'; } int conv(char c){ if (c == 'v') return 3; if (c == '^') return 2; if (c == '<') return 1; if (c == '>') return 0; } void Init(){ cin >> n >> m; pii s, t; for (int i = 1; i <= n; ++i){ cin >> S[i]; S[i] = " " + S[i]; for (int j = 1; j <= m; ++j){ if (S[i][j] == 'o') s = {i, j}; if (S[i][j] == 'x') t = {i, j}; } } memset(d, 0x3f, sizeof(d)); d[s.fi][s.se] = 0; queue <pii> Q; Q.push(s); while (!Q.empty()){ auto i = Q.front(); Q.pop(); if (i == t) break; if (S[i.fi][i.se] == '.') continue; if (S[i.fi][i.se] == 'o'){ for (int j = 0; j < 4; ++j){ d[i.fi + dx[j]][i.se + dy[j]] = 1; Q.push({i.fi + dx[j], i.se + dy[j]}); trace[i.fi + dx[j]][i.se + dy[j]] = c(j); } } else{ int j = conv(S[i.fi][i.se]); if (d[i.fi + dx[j]][i.se + dy[j]] != inf) continue; d[i.fi + dx[j]][i.se + dy[j]] = d[i.fi][i.se] + 1; trace[i.fi + dx[j]][i.se + dy[j]] = trace[i.fi][i.se]; Q.push({i.fi + dx[j], i.se + dy[j]}); } } if (d[t.fi][t.se] != inf){ cout << ":)\n"; cout << trace[t.fi][t.se]; } else{ cout << ":("; } } #define taskname "patkice" signed main(){ faster if (fopen(taskname ".inp", "r")){ freopen(taskname ".inp", "r", stdin); freopen(taskname ".out", "w", stdout); } int tt = 1; //cin >> tt; while (tt--){ Init(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4180 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4180 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4180 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |