結果

問題 No.1638 Robot Maze
ユーザー karinohitokarinohito
提出日時 2021-08-06 21:41:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,733 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 188,580 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 02:58:13
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 4 ms
4,348 KB
testcase_39 AC 4 ms
4,348 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 5 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 4 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
testcase_47 AC 4 ms
4,348 KB
testcase_48 AC 4 ms
4,348 KB
testcase_49 AC 4 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;
Graph G;
vll E;
vector<bool> seen;
ll k = 0;
void dfs(int v) {
	seen[v] = true; // v を訪問済にする

	// v から行ける各頂点 next_v について
	E[v] = k;
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue; // next_v が探索済だったらスルー
		k++;
		dfs(next_v); // 再帰的に探索
	}
	E[v] = k - E[v];
}

int main() {
	ll H,W;
	cin>>H>>W;
	ll U,D,R,L,K,P;
	cin>>U>>D>>R>>L>>K>>P;
	priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>> Q;
	ll XS,YS,XT,YT;
	cin>>XS>>YS>>XT>>YT;
	XS--;XT--;YS--;YT--;
	vector<vll> C(H,vll(W));
	rep(h,H){
		string S;
		cin>>S;
		rep(w,W){
			if(S[w]=='.')C[h][w]=0;
			else if(S[w]=='@')C[h][w]=1;
			else C[h][w]=2;
		}


	}


	vector<vector<bool>> seen(H,vector<bool> (W,false));
	vector<vll> dist(H,vll(W,1e18));
	dist[XS][YS]=0;
	Q.push(make_tuple(0,XS,YS));
	vll dx={1,-1,0,0};
	vll dy={0,0,1,-1};
	vll dp={D,U,R,L};
	while(!Q.empty()){
		
		auto p=Q.top();
		Q.pop();
		ll c=get<0>(p);
		ll y=get<2>(p);
		ll x=get<1>(p);
		if(seen[x][y])continue;
		seen[x][y]=true;
		rep(i,4){
			ll nx=x+dx[i];
			ll ny=y+dy[i];
			if(nx<0||x+dx[i]>=H||y+dy[i]<0||y+dy[i]>=W)continue;
			if(C[nx][ny]==2)continue;
			ll HH=0;
			if(C[nx][ny]==1)HH+=P;
			if(dist[nx][ny]<dist[x][y]+HH+dp[i])continue;
			dist[nx][ny]=dist[x][y]+HH+dp[i];
			Q.push(make_tuple(dist[nx][ny],nx,ny));
		}
	}
	if(dist[XT][YT]<=K)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}
0