結果

問題 No.8063 幅優先探索
ユーザー alorie10
提出日時 2020-04-01 22:08:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 172,932 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-06-27 11:02:14
合計ジャッジ時間 2,159 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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