結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  T1610 | 
| 提出日時 | 2019-03-31 22:50:10 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 22 ms / 5,000 ms | 
| コード長 | 2,305 bytes | 
| コンパイル時間 | 1,718 ms | 
| コンパイル使用メモリ | 175,040 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-22 14:29:09 | 
| 合計ジャッジ時間 | 2,750 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
#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;
}
            
            
            
        