Submission #1649751


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
// #define int unsigned long long

typedef pair<int,int> P;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int r,c;
int sx,sy;
int gx,gy;

int tesuu[101][101];
string maze[101];

const int INF=1e9;

int bfs(){

	queue< pair<int , int > > que;

	for(int y=0;y<r;y++){
		for(int x=0;x<c;x++){
			tesuu[y][x]=INF;
		}
	}

	// for(int y=0;y<r;y++){
	// 	for(int x=0;x<c;x++){
	// 		cout<<tesuu[y][x]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	// 	cout<<"---------------------------"<<endl;


	que.push( make_pair(sx,sy) );
	tesuu[sy][sx]=0;

	// for(int y=0;y<r;y++){
	// 	for(int x=0;x<c;x++){
	// 		cout<<tesuu[y][x]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	// cout<<"---------------------------"<<endl;

	while(!que.empty()){


		pair<int , int > tmp;
		tmp=que.front();
		que.pop();

		int x=tmp.first;
		int y=tmp.second;

		if(x==gx&&y==gy)break;

		for(int i=0;i<4;i++){
			int mx=x+dx[i];
			int my=y+dy[i];

			if(mx<0||my<0)continue;
			if(mx>=c||my>=r)continue;

			if(maze[my][mx]!='#'&&tesuu[my][mx]==INF){
				que.push( make_pair(mx, my)) ;
				tesuu[my][mx]=tesuu[y][x]+1;
			}
		}

		// for(int y=0;y<r;y++){
		// for(int x=0;x<c;x++){
		// 	cout<<tesuu[y][x]<<" ";
		// }
		// cout<<endl;
	// }

	// cout<<"---------------------------"<<endl;



	}

	return tesuu[gy][gx];
}

signed main(){
	
	cin>>r>>c>>sy>>sx>>gy>>gx;

	sx--;
	sy--;
	gx--;
	gy--;

	for(int i=0;i<r;i++){
		cin>>maze[i];
	}

	cout<<bfs()<<endl;




}

Submission Info

Submission Time
Task C - 幅優先探索
User Agodoriru
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1692 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt
All subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt
Case Name Status Exec Time Memory
subtask0_sample01.txt AC 1 ms 256 KB
subtask0_sample02.txt AC 1 ms 256 KB
subtask0_sample03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 1 ms 256 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 256 KB
subtask1_15.txt AC 1 ms 256 KB
subtask1_16.txt AC 1 ms 256 KB
subtask1_17.txt AC 1 ms 256 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 1 ms 256 KB
subtask1_21.txt AC 1 ms 256 KB
subtask1_22.txt AC 1 ms 256 KB