結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-15 17:20:01 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 5,000 ms |
| コード長 | 1,509 bytes |
| コンパイル時間 | 3,643 ms |
| コンパイル使用メモリ | 295,332 KB |
| 実行使用メモリ | 15,616 KB |
| 最終ジャッジ日時 | 2025-10-15 17:20:07 |
| 合計ジャッジ時間 | 5,310 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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=1e10+10;
vector<ll> dist(N*N, INF);
dist[start]=0;
priority_queue<ll> pq;pq.emplace(-start);
const int mask=(1<<20)-1;
while (!pq.empty()) {
auto x=-pq.top(); pq.pop();
auto [dv,v]=pair(x>>20,x&mask);
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<<20)+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;
}