結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
neterukun
|
| 提出日時 | 2022-04-12 21:06:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,125 bytes |
| コンパイル時間 | 1,075 ms |
| コンパイル使用メモリ | 86,204 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-21 06:44:46 |
| 合計ジャッジ時間 | 2,243 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 7 |
ソースコード
#include <iostream>
#include <tuple>
#include <vector>
#include <queue>
const int di[] = {0, 0, 1, -1};
const int dj[] = {1, -1, 0, 0};
std::vector<std::vector<long long>> dijkstra(const std::vector<std::vector<long long>> &grid, int si, int sj) {
using P = std::tuple<long long, int, int>;
int h = grid.size();
int w = grid[0].size();
std::vector<std::vector<long long>> distance(h, std::vector<long long>(w, 1LL << 60));
distance[si][sj] = 0LL;
std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
pq.emplace(0LL, si, sj);
while (not pq.empty()) {
auto p = pq.top();
pq.pop();
int& i = std::get<1>(p);
int& j = std::get<2>(p);
if (distance[i][j] < std::get<0>(p)) continue;
for (int k = 0; k < 4; k++) {
int nxt_i = i + di[k];
int nxt_j = j + dj[k];
if (nxt_i < 0 || h <= nxt_i) continue;
if (nxt_j < 0 || w <= nxt_j) continue;
if (distance[nxt_i][nxt_j] > distance[i][j] + grid[nxt_i][nxt_j]) {
distance[nxt_i][nxt_j] = distance[i][j] + grid[nxt_i][nxt_j];
pq.emplace(distance[nxt_i][nxt_j], nxt_i, nxt_j);
}
}
}
return distance;
}
int main() {
long long v;
int n, oj, oi;
std::cin >> n >> v >> oj >> oi;
oj -= 1;
oi -= 1;
std::vector<std::vector<long long>> l(n, std::vector<long long>(n, 0));
for (auto& inner : l) {
for (auto& val : inner) {
std::cin >> val;
}
}
auto distance = dijkstra(l, 0, 0);
if (v - distance[n - 1][n - 1] > 0) {
std::cout << "YES" << std::endl;
return 0;
}
if (oi == -1 && oj == -1) {
std::cout << "NO" << std::endl;
return 0;
}
if (v - distance[oi][oj] <= 0) {
std::cout << "NO" << std::endl;
return 0;
}
v -= distance[oi][oj];
v *= 2;
auto mid_distance = dijkstra(l, oi, oj);
if (v - distance[n - 1][n - 1] > 0) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
}
neterukun