結果

問題 No.20 砂漠のオアシス
ユーザー poohbearpoohbear
提出日時 2020-06-18 20:16:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,867 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 212,228 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-16 12:18:24
合計ジャッジ時間 3,174 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//グリッド上のダイクストラ
ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1,0,0};

vector<vector<ll> > g;//gはある座標から動くときにかかるコスト,distは最短距離

ll n;

vector<vector<ll> > dijkstra(ll sx, ll sy){
    vector<vector<ll> >dist(n,vector<ll>(n,INF));
    dist[sx][sy] = 0;
    priority_queue<PP,vector<PP>,greater<PP> >pq;
    pq.push(PP(0,P(sx,sy)));

    while(!pq.empty()){
        PP p = pq.top();
        pq.pop();
        ll c = p.first;
        ll vx = p.second.first;
        ll vy = p.second.second;

        rep(i,4){
            ll nx,ny;
            nx = vx + dx[i];
            ny = vy + dy[i];
            if (nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
            if (dist[nx][ny] <= g[nx][ny] + c) continue;
            dist[nx][ny] = g[nx][ny] + c;
            pq.push(PP(dist[nx][ny], P(nx, ny)));
        }
    }
    return dist;
}

int main(){
    ll v,ox,oy;
    cin >> n >> v >> ox >> oy;
    g.resize(n);
    rep(i,n)g[i].resize(n);
    rep(i,n)rep(j,n)cin>>g[i][j];
    v -= g[0][0];
    auto d = dijkstra(0,0);
    bool ans=false;
    if(d[n-1][n-1]<v){
        ans = true;
    }
    if(ox!=0){
        ox--;oy--;
        ll o = d[ox][oy];
        v -= o;
        if(v>0){
            v *= 2;
            auto last = dijkstra(ox,oy);
            v -= last[n-1][n-1];
            if(v>0)ans = true;
        }
    }
    if(ans)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
0