結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2020-04-01 22:09:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 1,785 ms |
| コンパイル使用メモリ | 177,444 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2024-06-27 11:02:45 |
| 合計ジャッジ時間 | 2,267 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 4 |
ソースコード
#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;
}
iqueue02