Submission #162417


Source Code Expand

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int,int> pii;
const double EPS = 1e-10;
const double PI  = acos(-1.0);



bool solve(){
	int r, c;
	P s, g;
	cin>> r>> c>> s.imag()>> s.real()>> g.imag()>> g.real();
	s = s + P(-1, -1);
	g = g + P(-1, -1);
	vector<vector<int> > a(r, vector<int>(c));
	for(int i=0;i<r;i++) for(int j=0;j<c;j++){
		char in;
		cin>> in;
		if(in == '.') a[i][j] = -1;
		if(in == '#') a[i][j] = -2;
	}

	queue<P> Q;
	Q.push(s);
	a[s.imag()][s.real()] = 0;
	P dd[4] = {P(0,1), P(1,0), P(-1,0), P(0,-1)};
	while(true){
		P p = Q.front();
		Q.pop();
//		cout<< " "<< p.real()<< " "<< p.imag()<< endl;
		if(p == g) break;
		for(int i=0;i<4;i++){
			P nex = p + dd[i];
			int x = nex.real(), y = nex.imag();
			if(0 <= x && x < c && 0 <= y && y < r && a[y][x] == -1){
				a[y][x] = a[p.imag()][p.real()] + 1;
				Q.push(nex);
			}
		}
	}
	
	cout<< a[g.imag()][g.real()]<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	solve();
	return 0;
}

 

Submission Info

Submission Time
Task C - 幅優先探索
User yokabb
Language C++ (G++ 4.6.4)
Score 100
Code Size 1502 Byte
Status AC
Exec Time 23 ms
Memory 932 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 21 ms 928 KB
subtask0_sample02.txt AC 21 ms 804 KB
subtask0_sample03.txt AC 21 ms 796 KB
subtask1_01.txt AC 21 ms 928 KB
subtask1_02.txt AC 21 ms 800 KB
subtask1_03.txt AC 21 ms 796 KB
subtask1_04.txt AC 20 ms 792 KB
subtask1_05.txt AC 21 ms 800 KB
subtask1_06.txt AC 21 ms 920 KB
subtask1_07.txt AC 21 ms 928 KB
subtask1_08.txt AC 21 ms 800 KB
subtask1_09.txt AC 23 ms 732 KB
subtask1_10.txt AC 22 ms 804 KB
subtask1_11.txt AC 22 ms 796 KB
subtask1_12.txt AC 22 ms 928 KB
subtask1_13.txt AC 21 ms 808 KB
subtask1_14.txt AC 21 ms 796 KB
subtask1_15.txt AC 22 ms 808 KB
subtask1_16.txt AC 20 ms 792 KB
subtask1_17.txt AC 22 ms 932 KB
subtask1_18.txt AC 23 ms 808 KB
subtask1_19.txt AC 21 ms 928 KB
subtask1_20.txt AC 22 ms 748 KB
subtask1_21.txt AC 21 ms 748 KB
subtask1_22.txt AC 21 ms 788 KB