結果

問題 No.3063 幅優先探索
ユーザー alorie10alorie10
提出日時 2020-04-01 22:08:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 170,664 KB
実行使用メモリ 9,200 KB
最終ジャッジ日時 2023-09-09 18:26:10
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int h,w,sx,sy,gx,gy,ch[1000][1000],nx,ny,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
string s[1000];
queue<P> que;
int main(void){
    cin>>h>>w>>sx>>sy>>gx>>gy;
    sx--,sy--,gx--,gy--;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    que.push({sx,sy});
    ch[sx][sy]=1;
    while(que.size()){
        P p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            nx=dx[i]+p.F,ny=dy[i]+p.S;
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]=='.'&&ch[nx][ny]==0){
                ch[nx][ny]=1+ch[p.F][p.S];
                que.push({nx,ny});
            }
        }
    }
    cout<<ch[gx][gy]-1<<endl;
}
0