結果

問題 No.3063 幅優先探索
ユーザー AquariusAquarius
提出日時 2020-04-01 21:46:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 814,272 KB
最終ジャッジ日時 2023-09-09 17:40:16
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 MLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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])));
    }
  }
}
0