結果

問題 No.20 砂漠のオアシス
コンテスト
ユーザー pessimist
提出日時 2025-10-15 16:36:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,514 bytes
コンパイル時間 4,113 ms
コンパイル使用メモリ 297,492 KB
実行使用メモリ 15,712 KB
最終ジャッジ日時 2025-10-15 16:36:14
合計ジャッジ時間 5,191 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N;
ll L[200*200];
vector<unordered_set<int>> graph;
vector<ll> dijkstra(int start) {
    const ll INF = 1e9 + 10;
    vector<ll> dist(N*N, INF);
    dist[start] = 0;
    using P = pair<ll,int>; 
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, start);
    while (!pq.empty()) {
        auto [dv, v] = pq.top(); pq.pop();
        if (dv != dist[v]) continue;
        for (auto &w : graph[v]) {
            ll dw = dv + L[w];
            if (dw < dist[w]) {
                dist[w] = dw;
                pq.emplace(dw, w);
            }
        }
    }
    return dist;
}

bool solve(){
    int V,Ox,Oy; cin>>N>>V>>Ox>>Oy;
    --Ox,--Oy; graph.resize(N*N,unordered_set<int>());
    const int oasis=Ox*N+Oy;
    const int start=0,goal=N*N-1;
    for(int i=0;i<N*N;++i) cin>>L[i];
    for(int i=0;i<N*N;++i){
        auto [x,y]=tuple(i/N,i%N);
        if(x){
            const int j=i-N;
            graph[i].insert(j);
            graph[j].insert(i);
        } 
        if(y){
            const int j=i-1;
            graph[i].insert(j);
            graph[j].insert(i);
        }
    }
    auto dist1=dijkstra(start);
    if(dist1[goal]<V) return true;
    if(Ox==-1) return false;
    auto dist2=dijkstra(oasis);
    V-=dist1[oasis];
    if(V<=0)return false;
    V*=2; V-=dist2[goal];
    return V>0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<(solve()?"YES":"NO")<<endl;
    return 0;
}
0