Submission #330076

#TimeUsernameProblemLanguageResultExecution timeMemory
330076phathnvPatkice (COCI20_patkice)C++11
30 / 50
1 ms384 KiB
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Patkice" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 102; const int INF = 1e9; int r, c, d[N][N]; char s[N][N]; map <char, int> dx, dy; void readInput(){ cin >> r >> c; for(int i = 1; i <= r; i++) cin >> (s[i] + 1); } bool inside(int x, int y){ return (1 <= x && x <= r && 1 <= y && y <= c); } int dfs(int x, int y){ if (!inside(x, y)) return INF; if (d[x][y] > -1) return d[x][y]; if (s[x][y] == 'x'){ d[x][y] = 0; return 0; } if (s[x][y] == '.'){ d[x][y] = INF; return INF; } if (s[x][y] == 'o'){ d[x][y] = INF; return INF; } int nxtX = x + dx[s[x][y]]; int nxtY = y + dy[s[x][y]]; d[x][y] = dfs(nxtX, nxtY) + 1; return d[x][y]; } void solve(){ int sX = -1, sY = -1; for(int i = 1; i <= r; i++) for(int j = 1; j <= c; j++) if (s[i][j] == 'o'){ sX = i; sY = j; } dx['^'] = -1; dx['v'] = 1; dy['<'] = -1; dy['>'] = 1; for(int i = 1; i <= r; i++) for(int j = 1; j <= c; j++) d[i][j] = -1; int bestDist = INF; char bestDir = '@'; if (bestDist > dfs(sX - 1, sY)){ bestDist = dfs(sX - 1, sY); bestDir = 'N'; } if (bestDist > dfs(sX + 1, sY)){ bestDist = dfs(sX + 1, sY); bestDir = 'S'; } if (bestDist > dfs(sX, sY - 1)){ bestDist = dfs(sX, sY - 1); bestDir = 'W'; } if (bestDist > dfs(sX, sY + 1)){ bestDist = dfs(sX, sY + 1); bestDir = 'E'; } if (bestDist >= INF){ cout << ":("; return; } cout << ":)\n" << bestDir; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); readInput(); solve(); return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   96 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   97 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...