結果
問題 | No.8063 幅優先探索 |
ユーザー |
![]() |
提出日時 | 2020-04-26 19:46:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 950 bytes |
コンパイル時間 | 6,993 ms |
コンパイル使用メモリ | 210,780 KB |
最終ジャッジ日時 | 2025-01-10 02:08:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; int R, C, sy, sx, gy, gx; vector<vector<char>> c; vector<vector<int>> ans; void bfs() { queue<pair<int, int>> q; q.push(make_pair(sy, sx)); ans[sy][sx] = 0; while (!q.empty()) { int y = q.front().first, x = q.front().second; q.pop(); int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1}; for (int i = 0; i < 4; ++i) { int ny = y + dy[i], nx = x + dx[i]; if (ny < 0 || R <= ny || nx < 0 || C <= nx) { continue; } if (c[ny][nx] == '#' || ans[ny][nx] != -1) { continue; } q.push(make_pair(ny, nx)); ans[ny][nx] = ans[y][x] + 1; } } } int main() { cin >> R >> C >> sy >> sx >> gy >> gx; c.resize(R, vector<char>(C)), ans.resize(R, vector<int>(C, -1)); for (int i = 0; i < R; ++i) { for (int j = 0; j < C; ++j) { cin >> c[i][j]; } } --sy, --sx, --gy, --gx; bfs(); cout << ans[gy][gx] << endl; }