Submission #162827


Source Code Expand

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
using i32=int;using i64=long long;using ll =i64;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//x,y,z
template <typename T> using X = vector<T>;template <typename T> using Y = vector<T>;template <typename T> using Z = vector<T>;
template <typename T> using YX = Y<X<T>>;//H*W M*N
template <typename T> using ZYX = Z<YX<T>>;

#define H(Map) Map.size()
#define W(Map) Map[0].size()

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef MODE_DEBUG
#define  DUMP(x)  cerr << #x << " = " << (x) <<endl
#define DEBUG(x) DUMP(x) << " (L" << __LINE__ << ")" << " " << __FILE__<<endl
#define CHECK(exp,act)  if(exp!=act){DUMP(exp);DEBUG(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#else
#define DUMP(x)
#define DEBUG(x)
#define CHECK(exp,act)
#define STOP(e)
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T>>& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

int INF=1<<28;
int  dx[4]={1,0,-1,0};
int  dy[4]={0,1,0,-1};
class Main{
public:	
	void run(){
		int R,C;cin >> R>>C;
		int sy,sx;cin >> sy >> sx;sy--;sx--;
		int gy,gx;cin >> gy >> gx;gy--;gx--;
		vector<string> board(R);
		REP(y,R){
			cin >>board[y];
		}
		vector<vector<int>> ds(R,vector<int>(C,INF));
		ds[sy][sx]=0;
		queue<pair<int,pair<int,int>>> que;
		que.push(make_pair(0,make_pair(sy,sx)));
		while(!que.empty()){
			pair<int,pair<int,int>> p=que.front();que.pop();

			REP(d,4){
				int ny=p.second.first+dy[d],nx=p.second.second+dx[d];
				if(!(IN(0,ny,R) && IN(0,nx,C)))continue;
				if(board[ny][nx]=='#')continue;
				if(p.first+1<ds[ny][nx]){
					ds[ny][nx]=p.first+1;
					que.push(make_pair(ds[ny][nx],make_pair(ny,nx)));
				}
			}
		}
		cout << ds[gy][gx]<<endl;
	}
};
 int main(){
 	cout <<fixed<<setprecision(15);
	ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Submission Info

Submission Time
Task C - 幅優先探索
User shimomire
Language C++11 (GCC 4.8.1)
Score 100
Code Size 3142 Byte
Status AC
Exec Time 25 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 932 KB
subtask0_sample02.txt AC 21 ms 928 KB
subtask0_sample03.txt AC 21 ms 928 KB
subtask1_01.txt AC 21 ms 804 KB
subtask1_02.txt AC 21 ms 932 KB
subtask1_03.txt AC 21 ms 804 KB
subtask1_04.txt AC 21 ms 804 KB
subtask1_05.txt AC 21 ms 804 KB
subtask1_06.txt AC 21 ms 928 KB
subtask1_07.txt AC 20 ms 924 KB
subtask1_08.txt AC 20 ms 916 KB
subtask1_09.txt AC 22 ms 732 KB
subtask1_10.txt AC 25 ms 816 KB
subtask1_11.txt AC 20 ms 924 KB
subtask1_12.txt AC 21 ms 800 KB
subtask1_13.txt AC 21 ms 804 KB
subtask1_14.txt AC 21 ms 928 KB
subtask1_15.txt AC 20 ms 916 KB
subtask1_16.txt AC 20 ms 800 KB
subtask1_17.txt AC 21 ms 924 KB
subtask1_18.txt AC 21 ms 928 KB
subtask1_19.txt AC 21 ms 932 KB
subtask1_20.txt AC 21 ms 928 KB
subtask1_21.txt AC 21 ms 928 KB
subtask1_22.txt AC 21 ms 928 KB