結果

問題 No.3063 幅優先探索
ユーザー iqueue02iqueue02
提出日時 2020-04-01 22:09:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 175,884 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2023-09-09 18:26:41
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int main() {
  int r, c;
  cin >> r >> c;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--; sy--;
  gx--; gy--;
  vector<string> g(r);
  rep(i,r) cin >> g[i];
  queue<P> que;
  vector<vector<int>> d(r, vector<int>(c,INF));
  que.push(make_pair(sx, sy));
  d[sx][sy] = 0;
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int x = p.first + dx[i], y = p.second + dy[i];
      if (x < 0 || y < 0 || x >= r || y >= c) continue;
      if (g[x][y] == '#') continue;
      if (d[x][y] != INF) continue;
      que.push(make_pair(x, y));
      d[x][y] = d[p.first][p.second] + 1;
    }
  }
  cout << d[gx][gy] << endl;
  return 0;
}
0