結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-17 03:20:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,549 bytes |
| コンパイル時間 | 2,161 ms |
| コンパイル使用メモリ | 208,720 KB |
| 最終ジャッジ日時 | 2025-02-08 07:31:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
// g <- pair < v , cost >
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
T INF = numeric_limits< T >::max();
vector<T> dist(graph.size(), INF);
priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
q.push({dist[s] = T(0), s});
while(!q.empty()){
auto [uc, ui] = q.top(); q.pop();
if(uc != dist[ui]) continue;
for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc)
q.push({dist[vi] = uc + vc, vi});
}
return dist;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll H,W,U,D,R,L,K,P; cin >> H >> W >> U >> D >> R >> L >> K >> P;
int xs,ys,xt,yt; cin >> xs >> ys >> xt >> yt; xs--, ys--, xt--, yt--;
vector<string> C(H);
rep(i,H) cin >> C[i];
vector<vector<pair<int,ll>>> G(H * W);
auto h = [&](int i, int j){ return i * W + j; };
int di[] = {-1, +1, 0, 0};
int dj[] = {0, 0, +1, -1};
ll cost[] = {U, D, R, L};
rep(i,H)rep(j,W)if(C[i][j] != '#')rep(d,4) {
int ni = i + di[d], nj = j + dj[d];
if(0 <= ni && ni < H && 0 <= nj && nj < W) {
if(C[ni][nj] == '.') {
G[h(i, j)].push_back({h(ni, nj), cost[d]});
} else if(C[ni][nj] == '@') {
G[h(i, j)].push_back({h(ni, nj), P});
}
}
}
cout << (dijkstra(G, h(xs, ys))[h(xt, yt)] <= K ? "Yes" : "No") << endl;
}