結果
問題 | No.20 砂漠のオアシス |
ユーザー |
![]() |
提出日時 | 2020-09-04 05:34:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 1,616 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 180,572 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 19:35:00 |
合計ジャッジ時間 | 2,532 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; const int INF = 1e9; const int dx[] = {1,0,-1,0}; const int dy[] = {0,1,0,-1}; int main() { int n, v, ox, oy; cin >> n >> v >> oy >> ox; ox--; oy--; VVI l(n, VI(n)); rep(i, n) rep(j, n) cin >> l[i][j]; auto min_cost = [&](int sx, int sy, int gx, int gy) { VVI dp(n, VI(n, INF)); priority_queue<tuple<int, int, int>> q; auto push = [&](int x, int y, int cost) { if (cost < dp[x][y]) { dp[x][y] = cost; q.emplace(-cost, x, y); } }; push(sx, sy, 0); while(!q.empty()) { int x, y, cost; tie(cost, x, y) = q.top(); q.pop(); cost = -cost; if (cost > dp[x][y]) continue; rep(k, 4) { int nx = x + dx[k], ny = y + dy[k]; if (!(0 <= nx && nx < n && 0 <= ny && ny < n)) continue; int nc = cost + l[nx][ny]; push(nx, ny, nc); } } return dp[gx][gy]; }; bool ok = false; if (min_cost(0, 0, n-1, n-1) < v) ok = true; if (ox >= 0) { int nv = v - min_cost(0, 0, ox, oy); if (nv > 0) { nv *= 2; if (min_cost(ox, oy, n-1, n-1) < nv) ok = true; } } cout << (ok ? "YES" : "NO") << endl; }