結果
問題 | No.3063 幅優先探索 |
ユーザー | alorie10 |
提出日時 | 2020-04-01 22:17:48 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 724 bytes |
コンパイル時間 | 1,497 ms |
コンパイル使用メモリ | 170,616 KB |
実行使用メモリ | 9,324 KB |
最終ジャッジ日時 | 2023-09-09 18:41:40 |
合計ジャッジ時間 | 2,223 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 46 ms
9,196 KB |
testcase_07 | AC | 46 ms
9,324 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
ソースコード
#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; }