結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-22 04:49:01 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,335 bytes |
| 記録 | |
| コンパイル時間 | 1,073 ms |
| コンパイル使用メモリ | 88,028 KB |
| 最終ジャッジ日時 | 2025-01-13 06:45:11 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 5 |
ソースコード
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template <class T>
using MaxHeap = std::priority_queue<T>;
const std::vector<std::pair<int, int>>
dxys{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void solve() {
int n, m, ox, oy;
std::cin >> n >> m >> ox >> oy;
--ox, --oy;
auto xss = vec(n, vec(n, 0));
for (auto& xs : xss) {
for (auto& x : xs) std::cin >> x;
}
auto dp = vec(n, vec(n, 0));
dp[0][0] = m;
MaxHeap<std::tuple<int, int, int>> heap;
heap.emplace(dp[0][0], 0, 0);
while (!heap.empty()) {
auto [d, x, y] = heap.top();
heap.pop();
if (d < dp[x][y]) continue;
if (x == ox && y == oy) dp[x][y] *= 2;
for (auto [dx, dy] : dxys) {
int nx = x + dx,
ny = y + dy;
if (nx < 0 || n <= nx ||
ny < 0 || n <= ny ||
dp[nx][ny] >= dp[x][y] - xss[nx][ny]) continue;
dp[nx][ny] = dp[x][y] - xss[nx][ny];
heap.emplace(dp[nx][ny], nx, ny);
}
}
std::cout << (dp[n - 1][n - 1] == 0 ? "NO" : "YES") << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}