結果

問題 No.20 砂漠のオアシス
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-05 13:33:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,517 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 174,568 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 15:14:54
合計ジャッジ時間 2,969 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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