結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
Aquarius
|
| 提出日時 | 2020-04-01 21:46:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 873 bytes |
| コンパイル時間 | 1,730 ms |
| コンパイル使用メモリ | 173,784 KB |
| 実行使用メモリ | 814,732 KB |
| 最終ジャッジ日時 | 2024-06-27 10:19:59 |
| 合計ジャッジ時間 | 4,136 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 3 WA * 3 MLE * 1 -- * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using PP = pair<int, int>;
using TT = pair<int, PP>;
int h, w;
int si, sj;
int gi, gj;
char s[1004][1004];
int main() {
cin >> h >> w >> si >> sj >> gi >> gj;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> s[i + 1][j + 1];
}
}
h += 2;
w += 2;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };
queue<TT> que;
que.push(TT(0, PP(si, sj)));
while (!que.empty()) {
TT t = que.front(); que.pop();
int d = t.first;
int i = t.second.first;
int j = t.second.second;
if (i < 0 || i >= h) continue;
if (j < 0 || j >= w) continue;
if (s[i][j] == '#') continue;
if (i == gi && j == gj) {
cout << d << endl;
return 0;
}
for (int k = 0; k < 4; ++k) {
que.push(TT(d + 1, PP(i + di[k], j + dj[k])));
}
}
}
Aquarius