Submission #420576


Source Code Expand

#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <limits>

#include <cmath>
#include <cstdio>

using namespace std;

vector<int> par;
void init(int n){
	par.resize(n);
	for(int x=0;x<n;++x){par[x]=x;}
}
//find root
int find(int x){
	if(par[x]==x){ return x; }
	else{ return par[x]=find(par[x]); }
}
//same root?
bool same(int x,int y){
	return find(x)==find(y);
}
//union!
void unions(int x,int y){
	x=find(x); y=find(y);
	if(x==y){ return; }
	par[x]=y;
}

vector<int> furui;
vector<int> furui_list;

void furui_init(int N){
	furui.assign(N+1,0);
	furui[0]=0; furui[1]=1;
	furui_list.reserve(500);
	for(int i=2;i<=N;++i){
		furui[i]=i;
		int limit=sqrt(i)+1;
		bool is_p=true;
		for(auto p:furui_list){
			is_p = i%p!=0;
			if(!is_p){ furui[i]=i/p; break;}
			if( p>limit+1 ){ break; }
		}
		if(is_p){ furui_list.push_back(i); }
	}
}

struct LoadTo{
	long to;
	long cost;
	LoadTo(long _to=-1,long _cost=-1):to(_to),cost(_cost){}
	bool operator <(const LoadTo &rhs){
		return cost < rhs.cost;
	}
};
vector<list<LoadTo>> lds;
vector<long> dtbl;
void dijk_init_tbl(long num){
	dtbl.assign(num,numeric_limits<long>::max());
}
void dijk_init(long num){
	dijk_init_tbl(num);
	lds.assign(num,list<LoadTo>());
}
void dijk_add(long from,long to,long cost){
	lds[from].emplace_back(to,cost);
	lds[to].emplace_back(from,cost);
}
void dijk_calc(long start){
	typedef pair<long,long> P;
	priority_queue< P,vector<P>,greater<P> > q; //コスト、町
	q.emplace(0, start);
	dtbl[start] = 0;

	while(!q.empty()){
		auto ex = q.top(); q.pop();
		auto n = ex.second;
		if(ex.first > dtbl[n]){continue;}
		for( auto it : lds[n] ){
			if(dtbl[n]+it.cost < dtbl[it.to] ){
				dtbl[it.to] = dtbl[n]+it.cost;
				q.emplace( dtbl[it.to], it.to );
			}
		}
	}
}

vector<vector<long>> wfdtbl;
const long wf_inf(){ return numeric_limits<long>::max()/2; }
void wf_init(long N){
	wfdtbl.assign(N, vector<long>(N,wf_inf()) );
	for(int i=0;i<N;++i){ wfdtbl[i][i]=0; }
}
void wf_add(long from,long to,long cost){
	wfdtbl[from][to] = cost;
}
bool wf_shortest(long from,long to,long cost){return wfdtbl[from][to] > cost;}
void wf_calc_only(long v1,long v2){
	const int N=wfdtbl.size();
	for(int i=0;i<N;++i){
		for(int j=0;j<N;++j){
			if( wfdtbl[i][j] - wfdtbl[i][v1] > wfdtbl[v1][v2]+wfdtbl[v2][j] ){ 
				wfdtbl[i][j]=wfdtbl[i][v1]+wfdtbl[v1][v2]+wfdtbl[v2][j];
			}
			if( wfdtbl[i][j] - wfdtbl[i][v2] > wfdtbl[v2][v1]+wfdtbl[v1][j] ){
				wfdtbl[i][j]=wfdtbl[i][v2]+wfdtbl[v2][v1]+wfdtbl[v1][j];
			}
		}
	}
}

void wf_calc(){
	const int N = wfdtbl.size();
	for(int k=0;k<N;++k){
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(wfdtbl[i][k]<wfdtbl[i][j]-wfdtbl[k][j]){
					wfdtbl[i][j] = wfdtbl[i][k] + wfdtbl[k][j];
				}
			}
		}
	}
}

int main(int argc,char **argv){
	int H,W;
	cin >> H >> W;
	vector< vector<char> > cells(H,vector<char>(W,'X'));
	struct Pos{
		int x,y;
		Pos(int _x,int _y):x(_x),y(_y){}
		Pos operator+(const Pos &lt){ return Pos(x+lt.x,y+lt.y); }
	};
	queue<Pos> work;

	for(int y=0;y<H;++y){
		for(int x=0;x<W;++x){
			cin >> cells[y][x];
			if( cells[y][x]=='s'){
				work.push(Pos(x,y));
				cells[y][x]='F';
			}
		}
	}

	Pos d[4]={Pos(1,0),Pos(0,1),Pos(-1,0),Pos(0,-1)};
	while(work.size()>0){
		Pos np = work.front();
		work.pop();
		for(int i=0;i<sizeof(d)/sizeof(Pos);++i){
			Pos xp = np + d[i];
			if(xp.x<0||xp.y<0||xp.x>=W||xp.y>=H){ continue; }
			char c = cells[xp.y][xp.x];
			if(c=='#' || c=='F'){ continue; }
			if(c=='g'){ cout<<"Yes"<<endl; return 0; }
			work.push(xp);
			cells[xp.y][xp.x] = 'F';
		}
	}
	cout<<"No"<<endl;

	return 0;
}

Submission Info

Submission Time
Task A - 深さ優先探索
User destroist
Language C++11 (GCC 4.9.2)
Score 100
Code Size 3884 Byte
Status AC
Exec Time 61 ms
Memory 1188 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 83
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_min_04.txt, 00_min_05.txt, 00_min_06.txt, 00_min_07.txt, 00_min_08.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rndhard_00.txt, 02_rndhard_01.txt, 02_rndhard_02.txt, 02_rndhard_03.txt, 02_rndhard_04.txt, 02_rndhard_05.txt, 02_rndhard_06.txt, 02_rndhard_07.txt, 02_rndhard_08.txt, 02_rndhard_09.txt, 02_rndhard_10.txt, 02_rndhard_11.txt, 02_rndhard_12.txt, 02_rndhard_13.txt, 02_rndhard_14.txt, 02_rndhard_15.txt, 02_rndhard_16.txt, 02_rndhard_17.txt, 02_rndhard_18.txt, 02_rndhard_19.txt, 02_rndhard_20.txt, 02_rndhard_21.txt, 02_rndhard_22.txt, 02_rndhard_23.txt, 02_rndhard_24.txt, 02_rndhard_25.txt, 02_rndhard_26.txt, 02_rndhard_27.txt, 02_rndhard_28.txt, 02_rndhard_29.txt, 02_rndhard_30.txt, 02_rndhard_31.txt, 02_rndhard_32.txt, 02_rndhard_33.txt, 02_rndhard_34.txt, 02_rndhard_35.txt, 02_rndhard_36.txt, 02_rndhard_37.txt, 02_rndhard_38.txt, 02_rndhard_39.txt, 03_rndhardsmall_00.txt, 03_rndhardsmall_01.txt, 03_rndhardsmall_02.txt, 03_rndhardsmall_03.txt, 03_rndhardsmall_04.txt, 03_rndhardsmall_05.txt, 03_rndhardsmall_06.txt, 03_rndhardsmall_07.txt, 03_rndhardsmall_08.txt, 03_rndhardsmall_09.txt
Case Name Status Exec Time Memory
00_min_01.txt AC 25 ms 808 KB
00_min_02.txt AC 26 ms 804 KB
00_min_03.txt AC 25 ms 928 KB
00_min_04.txt AC 25 ms 928 KB
00_min_05.txt AC 25 ms 800 KB
00_min_06.txt AC 26 ms 840 KB
00_min_07.txt AC 25 ms 928 KB
00_min_08.txt AC 25 ms 928 KB
00_sample_01.txt AC 24 ms 928 KB
00_sample_02.txt AC 25 ms 928 KB
00_sample_03.txt AC 26 ms 800 KB
00_sample_04.txt AC 24 ms 800 KB
00_sample_05.txt AC 26 ms 928 KB
01_rnd_00.txt AC 50 ms 1060 KB
01_rnd_01.txt AC 53 ms 1064 KB
01_rnd_02.txt AC 56 ms 1044 KB
01_rnd_03.txt AC 57 ms 984 KB
01_rnd_04.txt AC 58 ms 984 KB
01_rnd_05.txt AC 51 ms 1064 KB
01_rnd_06.txt AC 61 ms 1064 KB
01_rnd_07.txt AC 59 ms 1056 KB
01_rnd_08.txt AC 52 ms 1056 KB
01_rnd_09.txt AC 52 ms 996 KB
01_rnd_10.txt AC 60 ms 1180 KB
01_rnd_11.txt AC 53 ms 1064 KB
01_rnd_12.txt AC 59 ms 1184 KB
01_rnd_13.txt AC 51 ms 1064 KB
01_rnd_14.txt AC 49 ms 1060 KB
01_rnd_15.txt AC 56 ms 1052 KB
01_rnd_16.txt AC 49 ms 1052 KB
01_rnd_17.txt AC 60 ms 1056 KB
01_rnd_18.txt AC 51 ms 1176 KB
01_rnd_19.txt AC 54 ms 1052 KB
02_rndhard_00.txt AC 51 ms 1184 KB
02_rndhard_01.txt AC 56 ms 1176 KB
02_rndhard_02.txt AC 54 ms 1064 KB
02_rndhard_03.txt AC 55 ms 1056 KB
02_rndhard_04.txt AC 52 ms 1048 KB
02_rndhard_05.txt AC 53 ms 1060 KB
02_rndhard_06.txt AC 51 ms 1056 KB
02_rndhard_07.txt AC 52 ms 1180 KB
02_rndhard_08.txt AC 50 ms 1056 KB
02_rndhard_09.txt AC 52 ms 1180 KB
02_rndhard_10.txt AC 51 ms 1052 KB
02_rndhard_11.txt AC 50 ms 1060 KB
02_rndhard_12.txt AC 50 ms 1064 KB
02_rndhard_13.txt AC 50 ms 1060 KB
02_rndhard_14.txt AC 51 ms 1060 KB
02_rndhard_15.txt AC 53 ms 1060 KB
02_rndhard_16.txt AC 50 ms 1052 KB
02_rndhard_17.txt AC 51 ms 1056 KB
02_rndhard_18.txt AC 51 ms 1056 KB
02_rndhard_19.txt AC 51 ms 1064 KB
02_rndhard_20.txt AC 50 ms 1060 KB
02_rndhard_21.txt AC 50 ms 1180 KB
02_rndhard_22.txt AC 50 ms 1060 KB
02_rndhard_23.txt AC 50 ms 1060 KB
02_rndhard_24.txt AC 53 ms 1064 KB
02_rndhard_25.txt AC 51 ms 1060 KB
02_rndhard_26.txt AC 53 ms 1052 KB
02_rndhard_27.txt AC 52 ms 1056 KB
02_rndhard_28.txt AC 51 ms 1188 KB
02_rndhard_29.txt AC 50 ms 1056 KB
02_rndhard_30.txt AC 52 ms 1056 KB
02_rndhard_31.txt AC 52 ms 1068 KB
02_rndhard_32.txt AC 51 ms 1052 KB
02_rndhard_33.txt AC 51 ms 1176 KB
02_rndhard_34.txt AC 50 ms 1172 KB
02_rndhard_35.txt AC 50 ms 1180 KB
02_rndhard_36.txt AC 51 ms 1176 KB
02_rndhard_37.txt AC 50 ms 1180 KB
02_rndhard_38.txt AC 51 ms 1176 KB
02_rndhard_39.txt AC 52 ms 964 KB
03_rndhardsmall_00.txt AC 26 ms 924 KB
03_rndhardsmall_01.txt AC 27 ms 804 KB
03_rndhardsmall_02.txt AC 26 ms 804 KB
03_rndhardsmall_03.txt AC 26 ms 928 KB
03_rndhardsmall_04.txt AC 26 ms 800 KB
03_rndhardsmall_05.txt AC 26 ms 804 KB
03_rndhardsmall_06.txt AC 26 ms 812 KB
03_rndhardsmall_07.txt AC 26 ms 804 KB
03_rndhardsmall_08.txt AC 26 ms 800 KB
03_rndhardsmall_09.txt AC 26 ms 792 KB