結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-04 02:44:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 878 bytes |
| コンパイル時間 | 5,263 ms |
| コンパイル使用メモリ | 197,976 KB |
| 最終ジャッジ日時 | 2025-01-15 19:33:16 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
struct place{
int y;
int x;
};
int R,C;
int dist[1000][1000];
int dy[4]={-1,1,0,0};
int dx[4]={0,0,-1,1};
place sn,gn,cn,nn;
string G[1000];
int main(){
int i,j;
cin>>R>>C>>sn.y>>sn.x>>gn.y>>gn.x;
--sn.y;
--sn.x;
--gn.y;
--gn.x;
for(i=0;i<R;++i)cin>>G[i];
for(i=0;i<R;++i)for(j=0;j<C;++j)dist[i][j]=-1;
dist[sn.y][sn.x]=0;
queue<place>que;
que.push(sn);
while(!que.empty()){
cn=que.front();
if(cn.y==gn.y && cn.x==gn.x)break;
que.pop();
for(i=0;i<4;++i){
nn.y=cn.y+dy[i];
nn.x=cn.x+dx[i];
if(nn.y>=0 && nn.y<R && nn.x>=0 && nn.x<C && dist[nn.y][nn.x]==-1){
dist[nn.y][nn.x]=dist[cn.y][cn.x]+1;
que.push(nn);
}
}
}
cout<<dist[gn.x][gn.y]<<"\n";
}