# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
698477 | Do_you_copy | Papričice (COCI20_papricice) | C++17 | 1 ms | 468 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 101 + 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |