結果

問題 No.3063 幅優先探索
ユーザー s0j1sans0j1san
提出日時 2020-04-01 21:53:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 703 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 177,556 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2023-09-09 18:00:54
合計ジャッジ時間 3,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
vector<int> mx={0,1,0,-1};vector<int> my={1,0,-1,0};
int R,C,sy,sx,gy,gx,y,x,Y,X;scanf("%d %d %d %d %d %d",&R,&C,&sy,&sx,&gy,&gx);
vector<vector<char>> c(R,vector<char>(C));vector<vector<int>> dist(R,vector<int>(C,-1));
for(int i=0;i<R;i++)for(int j=0;j<C;j++)cin>>c[i][j];
queue<int> que;que.push(sy-1);que.push(sx-1);dist[sy-1][sx-1]=0;
while(!que.empty())
{
  y=que.front();que.pop();x=que.front();que.pop();
  for(int i=0;i<4;i++)
 {
    Y=y+my[i];X=x+mx[i];
    if(c[Y][X]!='.'||dist[Y][X]!=-1)continue;
    dist[Y][X]=dist[y][x]+1;
    que.push(Y);que.push(X);
    if(Y==gy-1&&X==gx-1){printf("%d\n",dist[gy-1][gx-1]);return 0;}
  }
}
}
0