結果

問題 No.3063 幅優先探索
ユーザー UtopiosphereUtopiosphere
提出日時 2020-04-01 22:05:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,264 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 177,612 KB
実行使用メモリ 8,296 KB
最終ジャッジ日時 2023-09-09 18:22:06
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;

}
0