結果
問題 |
No.8063 幅優先探索
|
ユーザー |
![]() |
提出日時 | 2021-04-18 16:30:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 1,734 ms |
コンパイル使用メモリ | 168,488 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 04:39:02 |
合計ジャッジ時間 | 2,419 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int h , w; cin >> h >> w; int y1 , x1; cin >> y1 >> x1; y1--; x1--; int y2 , x2; cin >> y2 >> x2; y2--; x2--; vector<string> s(h); for (int i = 0 ; i < h; i++) cin >> s[i]; cout << abs(x1 - x2) + abs(y1 - y2) << endl; /* queue<int> qx; queue<int> qy; qx.push(x1); qy.push(y1); s[y1][x1] = 'A'; vector<vector<int>> a(h , vector<int>(w , 0)); while (!qx.empty()) { int x = qx.front(); int y = qy.front(); qx.pop(); qy.pop(); if (x == x2 && y == y2) { cout << a[y][x] << endl; return 0; } if (x + 1 < w && s[y][x + 1] == '.') { qx.push(x + 1); qy.push(y); s[y][x + 1] = 'A'; a[y][x + 1] = a[y][x] + 1; } if (x - 1 >= 0 && s[y][x - 1] == '.') { qx.push(x - 1); qy.push(y); s[y][x - 1] = 'A'; a[y][x - 1] = a[y][x] + 1; } if (y + 1 < h && s[y + 1][x] == '.') { qx.push(x); qy.push(y + 1); s[y + 1][x] = 'A'; a[y + 1][x] = a[y][x] + 1; } if (y - 1 >= 0 && s[y - 1][x] == '.') { qx.push(x); qy.push(y - 1); s[y - 1][x] = 'A'; a[y - 1][x] = a[y][x] + 1; } } */ return 0; }