結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
Example0911
|
| 提出日時 | 2021-08-06 21:36:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,957 bytes |
| コンパイル時間 | 2,333 ms |
| コンパイル使用メモリ | 205,312 KB |
| 最終ジャッジ日時 | 2025-01-23 14:47:18 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
int N, M;
vector<pair<ll, ll>>edge[100010];
vector<ll> dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>>pq;
vector<ll>dist(N * M, INF);
dist[s] = 0;
pq.push({ dist[s],s });
while (!pq.empty()) {
P p = pq.top(); pq.pop();
ll d = p.first, from = p.second;
if (dist[from] < d)continue;
for (auto nv : edge[from]) {
ll to = nv.first; ll cost = nv.second;
if (dist[from] + cost < dist[to]) {
dist[to] = dist[from] + cost;
pq.push({ dist[to],to });
}
}
}
return dist;
}
int f(int i, int j) {
return i * M + j;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
int U, D, R, L, K, p; cin >> U >> D >> R >> L >> K >> p;
int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
vector<vector<char>>C(N, vector<char>(M));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> C[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (C[i][j] == '#')continue;
int cost = 0;
// i - 1
if (i > 0 && C[i - 1][j] != '#') {
cost = U;
if (C[i - 1][j] == '@')cost += p;
edge[f(i, j)].push_back({ f(i - 1, j), cost });
}
// i + 1
if (i < N - 1 && C[i + 1][j] != '#') {
cost = D;
if (C[i + 1][j] == '@')cost += p;
edge[f(i, j)].push_back({ f(i + 1, j), cost });
}
// j + 1
if (j < M - 1 && C[i][j + 1] != '#') {
cost = R;
if (C[i][j + 1] == '@')cost += p;
edge[f(i, j)].push_back({ f(i, j + 1), cost });
}
// j - 1
if (j > 0 && C[i][j - 1] != '#') {
cost = L;
if (C[i][j - 1] == '@')cost += p;
edge[f(i, j)].push_back({ f(i, j - 1), cost });
}
}
}
auto d = dijkstra(f(sx, sy));
int ans = d[f(gx, gy)];
if (ans <= K)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
Example0911