結果

問題 No.20 砂漠のオアシス
ユーザー poohbearpoohbear
提出日時 2020-06-18 23:17:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,822 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 212,792 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-16 12:28:26
合計ジャッジ時間 3,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 27 ms
4,496 KB
testcase_06 AC 26 ms
4,376 KB
testcase_07 AC 27 ms
4,380 KB
testcase_08 AC 27 ms
4,380 KB
testcase_09 AC 26 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,500 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 7 ms
4,376 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[vx][vy] + c) continue;
            dist[nx][ny] = g[vx][vy] + 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];
    auto d = dijkstra(0,0);
    bool ans=false;
    if(d[n-1][n-1]<v){
        ans = true;
    }
    if(ox!=0){
        ox--;oy--;
        v -= d[ox][oy];
        v -= g[ox][oy];
        v *= 2;
        v += g[ox][oy];
        auto last = dijkstra(ox,oy);
        if(v-last[n-1][n-1]>0)ans = true;
    }
    if(ans)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
0