結果

問題 No.20 砂漠のオアシス
ユーザー KudeKude
提出日時 2020-09-04 05:34:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,616 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 178,936 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 07:52:20
合計ジャッジ時間 3,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 27 ms
4,380 KB
testcase_07 AC 27 ms
4,384 KB
testcase_08 AC 20 ms
4,376 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0