제출 #1239147

#제출 시각아이디문제언어결과실행 시간메모리
1239147ghassanhasanPatkice II (COCI21_patkice2)C++20
0 / 110
7 ms16196 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2e3 + 5; const int di[] = {0, 0, 1, -1}; const int dj[] = {-1, 1, 0, 0}; const string C = "<>v^"; vector grid(N, string()); vector par(N, vector<int>(N, -1)); int n, m, si, sj, ei, ej; bool valid(int i, int j) { return i >= 0 && j >= 0 && i < n && j < m && par[i][j] == -1; } void dfs(int i, int j, vector<pair<int, int>> &ret) { ret.emplace_back(i, j); for (int k = 0; k < 4; k++) { int ni = i + di[k], nj = j + dj[k]; if (valid(ni, nj) && grid[i][j] == C[k]) { par[ni][nj] = k; dfs(ni, nj, ret); } } } int bfs() { vector<array<int, 3>> q; q.push_back({si, sj, 0}); par[si][sj] = -5; vector<pair<int, int>> cur; for (int st = 0; st < q.size(); st++) { auto [i, j, c] = q[st]; dfs(i, j, cur); if (par[ei][ej] != -1) return c; for (auto [x, y] : cur) { for (int k = 0; k < 4; k++) { int ni = x + di[k], nj = y + dj[k]; if (valid(ni, nj)) { par[ni][nj] = k; q.push_back({ni, nj, c + 1}); } } } cur.clear(); } return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> grid[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == 'o') si = i, sj = j; else if (grid[i][j] == 'x') ei = i, ej = j; } } cout << bfs() << endl; while (par[ei][ej] != -5) { int k = par[ei][ej]; int i = ei - di[k], j = ej - dj[k]; grid[i][j] = C[k]; ei = i; ej = j; } grid[si][sj] = 'o'; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << grid[i][j]; } cout << '\n'; } cout.flush(); system("pause"); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:95:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     system("pause");
      |     ~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...