結果
| 問題 | No.8063 幅優先探索 |
| コンテスト | |
| ユーザー |
Utopiosphere
|
| 提出日時 | 2020-04-01 22:05:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,264 bytes |
| 記録 | |
| コンパイル時間 | 1,849 ms |
| コンパイル使用メモリ | 181,672 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-06-27 10:57:45 |
| 合計ジャッジ時間 | 2,432 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;
int H, W, a, b;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int bfs(int x, int y, vector<vector<char>> &A){
queue<Pint> Next;
Next.push(Pint(x, y));
vector<vector<int>> dist(H, vector<int> (W, 1000000007));
dist.at(x).at(y) = 0;
while(Next.size() != 0){
Pint p = Next.front();
Next.pop();
for(int i = 0; i < 4; i++){
int nx = p.first + dx.at(i), ny = p.second + dy.at(i);
if (nx < H && 0 <= nx && ny < W && 0 <= ny && dist.at(nx).at(ny) == 1000000007 && A.at(nx).at(ny) == '.'){
Next.push(Pint(nx, ny));
dist.at(nx).at(ny) = dist.at(p.first).at(p.second) + 1;
}
}
}
int value = dist.at(a - 1).at(b - 1);
return value;
}
int main() {
cin >> H >> W;
int x, y;
cin >> x >> y >> a >> b;
vector<vector<char>> A(H, vector<char>(W));
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
cin >> A.at(i).at(j);
}
}
cout << bfs(x - 1, y - 1, A) << endl;
}
Utopiosphere