結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-08-06 21:37:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,092 bytes |
| コンパイル時間 | 1,313 ms |
| コンパイル使用メモリ | 124,692 KB |
| 最終ジャッジ日時 | 2025-01-23 14:49:19 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
char c[100][100];
int h, w;
int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, 1, -1};
bool is_in_field(int i, int j){
return i >= 0 && i < h && j >= 0 && j < w;
}
const ll INF = 1e18;
using T = tuple<ll, int, int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> h >> w;
vector<ll> cost(4);
ll k, p;
for(int i = 0; i < 4; i++) cin >> cost[i];
cin >> k >> p;
int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
xs--; ys--; xt--; yt--;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
cin >> c[i][j];
}
}
vector<vector<ll>> dist(h, vector<ll>(w, INF));
priority_queue<T, vector<T>, greater<T>> que;
auto add = [&](ll d, int x, int y){
if(d < dist[x][y]){
dist[x][y] = d;
que.push(T(d, x, y));
}
};
add(0, xs, ys);
while(!que.empty()){
auto [d, x, y] = que.top(); que.pop();
// cout << x << ' ' << y << ' ' << d << endl;
for(int i = 0; i < 4; i++){
int x_to = x+dh[i];
int y_to = y+dw[i];
if(!is_in_field(x_to, y_to)) continue;
if(c[x_to][y_to] == '#') continue;
ll nx_dist = d+cost[i];
if(c[x_to][y_to] == '@') nx_dist += p;
add(nx_dist, x_to, y_to);
}
}
if(dist[xt][yt] <= k) cout << "Yes" << endl;
else cout << "No" << endl;
}
milanis48663220