結果

問題 No.1638 Robot Maze
ユーザー 沙耶花
提出日時 2021-08-06 21:56:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 4,460 ms
コンパイル使用メモリ 259,436 KB
最終ジャッジ日時 2025-01-23 15:14:52
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000

int main(){
	
	int h,w;
	cin>>h>>w;
	
	vector<int> dx = {0,0,1,-1},dy = {-1,1,0,0};
	vector<long long> cost;
	{
		long long a,b,c,d;
		cin>>a>>b>>c>>d;
		
		cost = {a,b,c,d};
	}
	
	long long K,P;
	cin>>K>>P;
	
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	sx--;sy--;tx--;ty--;
	
	vector<string> S(h);
	rep(i,h)cin>>S[i];
	
	vector dis(h,vector<long long>(w,Inf));
	
	dis[sx][sy] = 0;
	priority_queue<pair<long long,pair<int,int>>,vector<pair<long long,pair<int,int>>>,greater<pair<long long,pair<int,int>>>> Q;
	Q.emplace(0,make_pair(sx,sy));
	
	while(Q.size()>0){
		long long D = Q.top().first;
		int y = Q.top().second.first,x = Q.top().second.second;
		Q.pop();
		if(dis[y][x]!=D)continue;
		rep(i,4){
			int yy = y + dy[i],xx = x+dx[i];
			if(yy<0||yy>=h||xx<0||xx>=w)continue;
			long long DD = D;
			DD += cost[i];
			if(S[yy][xx]=='#')continue;
			if(S[yy][xx]=='@')DD += P;
			if(dis[yy][xx]>DD){
				dis[yy][xx] = DD;
				Q.emplace(DD,make_pair(yy,xx));
			}
		}
	}
	
	long long temp = dis[tx][ty];
	if(temp>K)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	
	return 0;
}
0