Submission #698478

#TimeUsernameProblemLanguageResultExecution timeMemory
698478Do_you_copyPapričice (COCI20_papricice)C++14
0 / 110
2 ms4180 KiB
#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 (stderr)

papricice.cpp: In function 'char c(int)':
papricice.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
   25 | }
      | ^
papricice.cpp: In function 'int conv(char)':
papricice.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^
papricice.cpp: In function 'int main()':
papricice.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
papricice.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...