結果

問題 No.20 砂漠のオアシス
ユーザー xuzijian629xuzijian629
提出日時 2018-11-02 22:18:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,873 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 210,504 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 22:37:29
合計ジャッジ時間 3,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, v, ox, oy;
    cin >> n >> v >> ox >> oy;
    ox--;
    oy--;

    vvi b(n, vi(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> b[i][j];
        }
    }

    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    auto ok = [&](int a, int b) {
        return 0 <= a && a < n && 0 <= b && b < n;
    };

    vvi d(n, vi(n, -1));
    d[0][0] = v;
    using ii = pair<int, int>;
    queue<ii> que;
    que.push(ii(0, 0));
    while (que.size()) {
        ii t = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int x = t.first + dx[i];
            int y = t.second + dy[i];
            if (ok(x, y)) {
                int vv = d[t.first][t.second] - b[x][y];
                if (vv > 0 && d[x][y] < vv) {
                    d[x][y] = vv;
                    que.push(ii(x, y));
                }
            }
        }
    }

    if (d[n - 1][n - 1] != -1) {
        cout << "YES" << endl;
        return 0;
    }

    if ((ox == -1 && oy == -1) || d[ox][oy] == -1) {
        cout << "NO" << endl;
        return 0;
    }

    v = d[ox][oy] * 2;

    d = vvi(n, vi(n, -1));
    d[ox][oy] = v;
    using ii = pair<int, int>;
    que.push(ii(ox, oy));
    while (que.size()) {
        ii t = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int x = t.first + dx[i];
            int y = t.second + dy[i];
            if (ok(x, y)) {
                int vv = d[t.first][t.second] - b[x][y];
                if (vv > 0 && d[x][y] < vv) {
                    d[x][y] = vv;
                    que.push(ii(x, y));
                }
            }
        }
    }

    cout << (d[n - 1][n - 1] == -1 ? "NO" : "YES") << endl;
}
0