結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2020-05-05 13:33:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 1,517 bytes |
| コンパイル時間 | 1,800 ms |
| コンパイル使用メモリ | 175,576 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 08:18:26 |
| 合計ジャッジ時間 | 2,757 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, V, Ox, Oy;
cin >> N >> V >> Ox >> Oy;
int L[220][220];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
L[i][j] = 100000;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> L[j + 1][i + 1];
}
}
struct book {
int vit, x, y, used;
};
priority_queue<book, vector<book>, function<bool(book, book)>> que(
[](book a, book b) {
if (a.used != b.used) return (bool)a.used;
return a.vit < b.vit;
});
que.push({V, 1, 1, 0});
int dp[220][220][2] = {};
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
while (!que.empty()) {
auto now = que.top();
que.pop();
if (now.x == N && now.y == N) {
cout << "YES" << endl;
return 0;
}
if (dp[now.x][now.y][now.used] >= now.vit)
continue;
dp[now.x][now.y][now.used] = now.vit;
if (now.x == Ox && now.y == Oy && now.used == 0) {
now.vit *= 2;
now.used = 1;
que.push(now);
continue;
}
for (int i = 0; i < 4; i++) {
int nx = now.x + dx[i], ny = now.y + dy[i];
int nv = now.vit - L[nx][ny];
if (nv > 0) {
que.push({nv, nx, ny, now.used});
}
}
}
cout << "NO" << endl;
}
maine_honzuki