結果

問題 No.20 砂漠のオアシス
ユーザー T1610T1610
提出日時 2019-03-31 22:50:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 2,305 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 174,880 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 04:05:16
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};

const int MAX_N = 210;
int d[MAX_N][MAX_N][2];
int L[MAX_N][MAX_N];

bool used[MAX_N][MAX_N][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i, MAX_N) rep(j, MAX_N) rep(k, 2) d[i][j][k] = -INF;
    int N, V, OX, OY;
    cin >> N >> V >> OX >> OY;
    --OX;
    --OY;
    rep(i, N) rep(j, N) cin >> L[i][j];
    d[0][0][0] = V;
    using P = pair<pii, pii>;
    priority_queue<P> q;
    q.push({{V, 0}, {0, 0}});

    auto isOutOfRange = [](int h, int w, int H, int W) {
        return h < 0 || h >= H || w < 0 || w >= W;
    };

    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int l = p.fi.fi, b = p.fi.se, x = p.se.se, y = p.se.fi;
        if (d[y][x][b] > l) continue;
        // cout << x << ", " << y << ", " << b << " -> " << l << endl;

        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (isOutOfRange(ny, nx, N, N)) continue;
            int nl = l - L[ny][nx];
            // cout << " " << nx << ", " << ny << ", " << b << " -> " << nl << endl; 
            if (d[ny][nx][b] < nl) {
                d[ny][nx][b] = nl;
                q.push({{nl, b}, {ny, nx}});
            }
            if (ny == OY && nx == OX && b == 0) {
                if (d[ny][nx][1] < nl * 2) {
                    d[ny][nx][1] = nl * 2;
                    q.push({{nl * 2, 1}, {ny, nx}});
                }
            }
        }
    }
    string yes = "YES", no = "NO";
    bool f = max(d[N-1][N-1][0], d[N-1][N-1][1]) > 0;
    cout << (f ? yes : no) << endl;

    // rep(i, N) {
    //     rep(j, N) {
    //         cout << " ("  << d[i][j][0] << ", " << d[i][j][1] <<") ";
    //     }
    //     cout << endl;
    // }
    return 0;
}
0