結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
alorie10
|
| 提出日時 | 2020-04-01 22:17:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 724 bytes |
| コンパイル時間 | 1,672 ms |
| コンパイル使用メモリ | 171,204 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-06-27 11:18:32 |
| 合計ジャッジ時間 | 2,266 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#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[1001][1001],nx,ny,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
string s[1001];
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&&ch[nx][ny]==0){
ch[nx][ny]=1+ch[p.F][p.S];
que.push({nx,ny});
}
}
}
cout<<ch[gx][gy]-1<<endl;
}
alorie10