結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-04-25 19:30:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 1,738 bytes |
| コンパイル時間 | 1,987 ms |
| コンパイル使用メモリ | 212,032 KB |
| 最終ジャッジ日時 | 2025-01-07 02:57:40 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
for(auto &e:u) fill_v<T>(e,v...);
}
//INSERT ABOVE HERE
signed main(){
Int n,v,sx,sy;
cin>>n>>v>>sx>>sy;
sx--;sy--;
auto ls=make_v<Int>(n,n);
for(Int i=0;i<n;i++)
for(Int j=0;j<n;j++)
cin>>ls[i][j];
auto dp=make_v<Int>(2,n,n);
fill_v<Int>(dp,0);
using T = tuple<Int, Int, Int>;
queue<T> qu;
dp[0][0][0]=v;
qu.emplace(0,0,0);
auto in=[&](Int y,Int x){return 0<=y&&y<n&&0<=x&&x<n;};
Int dy[]={0,0,1,-1};
Int dx[]={1,-1,0,0};
while(!qu.empty()){
Int f,y,x;
tie(f,y,x)=qu.front();qu.pop();
assert(dp[f][y][x]>0);
if(!f&&y==sy&&x==sx&&dp[1][y][x]<dp[f][y][x]*2){
dp[1][y][x]=dp[f][y][x]*2;
qu.emplace(1,y,x);
}
for(Int k=0;k<4;k++){
Int ny=y+dy[k],nx=x+dx[k];
if(!in(ny,nx)||dp[f][ny][nx]>=dp[f][y][x]-ls[ny][nx]) continue;
if(dp[f][y][x]-ls[ny][nx]<=0) continue;
dp[f][ny][nx]=dp[f][y][x]-ls[ny][nx];
qu.emplace(f,ny,nx);
}
}
cout<<(max(dp[0][n-1][n-1],dp[1][n-1][n-1])>0?"YES":"NO")<<endl;
return 0;
}
beet