結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
mmn15277198
|
| 提出日時 | 2021-04-18 16:28:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,625 bytes |
| コンパイル時間 | 1,955 ms |
| コンパイル使用メモリ | 177,248 KB |
| 実行使用メモリ | 9,216 KB |
| 最終ジャッジ日時 | 2024-07-04 04:38:50 |
| 合計ジャッジ時間 | 2,540 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 2 |
ソースコード
#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];
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;
cout << abs(x1 - x2) + abs(y1 - y2) << endl;
return 0;
//break;
}
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;
}
}
/*
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
*/
return 0;
}
mmn15277198