結果

問題 No.3063 幅優先探索
ユーザー kotatsugamekotatsugame
提出日時 2020-04-01 22:24:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 75,484 KB
実行使用メモリ 9,220 KB
最終ジャッジ日時 2023-09-09 18:58:33
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 49 ms
9,220 KB
testcase_07 AC 48 ms
9,208 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int R,C,sx,sy,gx,gy;
string s[1000];
int d[1000][1000];
int dx[4]={0,1,0,-1};
main()
{
	cin>>R>>C>>sx>>sy>>gx>>gy;
	for(int i=0;i<R;i++)cin>>s[i];
	for(int i=0;i<R;i++)for(int j=0;j<C;j++)d[i][j]=1e9;
	sx--,sy--,gx--,gy--;
	d[sx][sy]=0;
	queue<pair<int,int> >P;
	P.push(make_pair(sx,sy));
	while(!P.empty())
	{
		int x=P.front().first,y=P.front().second;
		P.pop();
		for(int r=0;r<4;r++)
		{
			int tx=x+dx[r],ty=y+dx[r^1];
			if(tx<0||ty<0||tx>=R||ty>=C||d[tx][ty]<=d[x][y]+1)continue;
			d[tx][ty]=d[x][y]+1;
			P.push(make_pair(tx,ty));
		}
	}
	cout<<d[gx][gy]<<endl;
}
0