結果

問題 No.20 砂漠のオアシス
ユーザー T1610T1610
提出日時 2019-03-31 22:31:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,299 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 175,004 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-05-02 03:10:19
合計ジャッジ時間 9,885 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];

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, vector<P>, greater<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