Submission #2972315


Source Code Expand

#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

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

typedef pair<int,int> P;
typedef pair<int,P> PP;
int R,C;
queue<PP> Q;
vector< vector<char> > VC;

void putQueue(int c,int y,int x){
	REP(i,4){
		if(y+dy[i] < 0 || y+dy[i] >= R)continue;
		if(x+dx[i] < 0 || x+dx[i] >= C)continue;
		if(VC[y+dy[i]][x+dx[i]] == '#')continue;
		Q.push(PP(c,P(y+dy[i],x+dx[i])));
		VC[y+dy[i]][x+dx[i]] = '#';
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> R >> C;
	int sy,sx;
	cin >> sy >> sx;
	int gy,gx;
	cin >> gy >> gx;
	sy--;sx--;gy--;gx--;
	VC = vector< vector<char> > (R,vector<char>(C,'#'));
	REP(i,R)REP(j,C)cin >> VC[i][j];
	Q.push(PP(0,P(sy,sx)));
	VC[0][0] = '#';
	while(!Q.empty()){
		PP pp = Q.front();Q.pop();
		if(pp.sec.fir == gy && pp.sec.sec == gx){
			cout << pp.fir << endl;
			return 0;
		}
		DUMP(pp);
		putQueue(pp.fir+1,pp.sec.fir,pp.sec.sec);
		DUMP(Q);
	}
	return 0;
}

Submission Info

Submission Time
Task C - 幅優先探索
User Daylight
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1817 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