結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
FSM
|
| 提出日時 | 2020-04-01 21:32:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,561 bytes |
| コンパイル時間 | 785 ms |
| コンパイル使用メモリ | 79,068 KB |
| 実行使用メモリ | 7,424 KB |
| 最終ジャッジ日時 | 2024-06-27 09:02:38 |
| 合計ジャッジ時間 | 1,642 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 4 |
ソースコード
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<queue>
#include<utility>
using graph = std::vector<std::vector<int>>;
const int INF = INT_MAX;
const int NOT_SEARCHED = 100000;
int s[2], g[2];
int h, w;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
void bfs(graph &meiro){
std::queue<std::pair<int, int>> que;
que.emplace(s[0], s[1]);
meiro[s[0]][s[1]] = 0;
while(!que.empty()){
std::pair<int, int> now = que.front();
que.pop();
int y = now.first;
int x = now.second;
for(int i = 0; i < 4; i++){
int next_x = x + dx[i];
int next_y = y + dy[i];
if(next_x < 0 || next_x >= w) continue;
if(next_y < 0 || next_y >= h) continue;
if(meiro[next_y][next_x] != INF){
if(meiro[next_y][next_x] > meiro[y][x] + 1){
meiro[next_y][next_x] = meiro[y][x] + 1;
que.emplace(next_y, next_x);
}
}
}
}
}
int main(){
std::cin >> h >> w;
std::cin >> s[0] >> s[1];
std::cin >> g[0] >> g[1];
// to 0 origin
s[0]--; s[1]--; g[0]--; g[1]--;
graph meiro(h, std::vector<int>(w, INF));
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
char c;
std::cin >> c;
if(c == '.'){
meiro[i][j] = NOT_SEARCHED;
}
}
}
bfs(meiro);
std::cout << meiro[g[0]][g[1]] << std::endl;
return 0;
}
FSM