結果
問題 | No.20 砂漠のオアシス |
ユーザー | fura |
提出日時 | 2020-01-06 19:24:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 1,278 bytes |
コンパイル時間 | 1,901 ms |
コンパイル使用メモリ | 177,820 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-11-23 00:06:02 |
合計ジャッジ時間 | 2,779 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;template<class T> struct edge{int to;T wt;edge(int to,const T& wt):to(to),wt(wt){}};template<class T> using weighted_graph=vector<vector<edge<T>>>;template<class T>vector<T> Dijkstra(const weighted_graph<T>& G,int s){const T INF=numeric_limits<T>::max();int n=G.size();vector<T> d(n,INF); d[s]=0;priority_queue<pair<T,int>> Q; Q.emplace(0,s);while(!Q.empty()){T d0=-Q.top().first;int u=Q.top().second; Q.pop();if(d0>d[u]) continue;for(const auto& e:G[u]){int v=e.to;if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);}}return d;}int main(){int n,hp,ox,oy,a[200][200];scanf("%d%d%d%d",&n,&hp,&ox,&oy); ox--; oy--;rep(i,n) rep(j,n) scanf("%d",&a[i][j]);weighted_graph<int> G(n*n);rep(i,n) rep(j,n) {if(i<n-1){G[i*n+j].emplace_back((i+1)*n+j,a[i+1][j]);G[(i+1)*n+j].emplace_back(i*n+j,a[i][j]);}if(j<n-1){G[i*n+j].emplace_back(i*n+(j+1),a[i][j+1]);G[i*n+(j+1)].emplace_back(i*n+j,a[i][j]);}}auto d=Dijkstra(G,0);if(hp>d[n*n-1]) return puts("YES"),0;if(ox==-1) return puts("NO"),0;auto d2=Dijkstra(G,oy*n+ox);puts(hp>d[oy*n+ox]&&2*(hp-d[oy*n+ox])>d2[n*n-1]?"YES":"NO");return 0;}