結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-15 16:44:46 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 5,000 ms |
| コード長 | 1,514 bytes |
| コンパイル時間 | 3,039 ms |
| コンパイル使用メモリ | 297,348 KB |
| 実行使用メモリ | 15,744 KB |
| 最終ジャッジ日時 | 2025-10-15 16:44:52 |
| 合計ジャッジ時間 | 4,323 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#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>>Oy>>Ox;
--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;
}