結果

問題 No.3063 幅優先探索
ユーザー 沙耶花沙耶花
提出日時 2020-04-01 22:11:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 208,456 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2023-09-09 18:29:19
合計ジャッジ時間 2,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
queue<pair<pair<int,int>,int>> que;

void push_que(int x,int y,int cnt){
	que.push(make_pair(make_pair(x+1,y),cnt+1));
	que.push(make_pair(make_pair(x-1,y),cnt+1));
	que.push(make_pair(make_pair(x,y+1),cnt+1));
	que.push(make_pair(make_pair(x,y-1),cnt+1));
	
}

int main(){
	int R,C;
	cin>>R>>C;
	swap(R,C);
	int sy,sx,gy,gx;
	cin>>sy>>sx>>gy>>gx;
	sx--;sy--;gx--;gy--;
	//swap(sx,sy);
	//swap(gx,gy);
	string s[R];
	for(int i=0;i<R;i++){
		cin>>s[i];
	}
	vector<vector<int>> mini(C,vector<int>(R,-1));//mini[x][y];
	mini[sx][sy]=0;
	push_que(sx,sy,0);
	
	while(true){
		if(que.size()==0)break;
		pair<pair<int,int>,int> a = que.front();
		que.pop();
		int x = a.first.first;
		int y = a.first.second;
		int c = a.second;
		if(x<0||x>=C)continue;
		if(y<0||y>=R)continue;
		if(s[y][x]=='#')continue;
		if(mini[x][y]!=-1)continue;
		mini[x][y]=c;
		push_que(x,y,c);
	}
	cout<<mini[gx][gy]<<endl;
	
	
	
	
	return 0;
}
0