結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2022-05-28 18:48:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,801 bytes |
| コンパイル時間 | 2,713 ms |
| コンパイル使用メモリ | 224,504 KB |
| 最終ジャッジ日時 | 2025-01-29 16:47:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 7 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <debug>
#else
#define debug(...) void(0)
#endif
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T>
istream& operator>>(istream&is,vector<T>&v){
for(T&p:v)is>>p;
return is;
}
template<typename T>
ostream& operator<<(ostream&os,const vector<T>&v){
if(&os==&cerr)os<<"[";
for(int i=0;i<v.size();i++){
os<<v[i];
if(i+1<v.size())os<<(&os==&cerr?",":" ");
}
if(&os==&cerr)os<<"]";
return os;
}
int dy[9]={-1,1,0,0,-1,-1,1,1,0};
int dx[9]={0,0,-1,1,-1,1,-1,1,0};
bool inyx(int y,int x,int h,int w){
return y>=0 and y<h and x>=0 and x<w;
}
template<typename T>
void fin(T a){
cout<<a<<endl;
exit(0);
}
template<typename T>
bool chmax(T &a,T b){
return (a<b&&(a=b,true));
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,v,ox,oy;cin>>n>>v>>ox>>oy;
ox--;oy--;
vector l(n,vector<int>(n));
cin>>l;
vector d(n,vector<int>(n,-1));
priority_queue<tuple<int,int,int>> que;
d[0][0]=v;
que.emplace(v,0,0);
while(que.size()){
auto [va,y,x]=que.top();que.pop();
if(d[y][x]>va)continue;
REP(dd,4){
int Y=y+dy[dd],X=x+dx[dd];
if(!inyx(Y,X,n,n))continue;
if(chmax(d[Y][X],va-l[Y][X]))
que.emplace(d[Y][X],Y,X);
}
}
if(d[n-1][n-1]>0)fin("YES");
if(ox<0||d[oy][ox]<=0)fin("NO");
v=d[oy][ox]*2;
REP(i,n)REP(j,n)d[i][j]=-1;
d[0][0]=v;
que.emplace(v,0,0);
while(que.size()){
auto [va,y,x]=que.top();que.pop();
if(d[y][x]>va)continue;
REP(dd,4){
int Y=y+dy[dd],X=x+dx[dd];
if(!inyx(Y,X,n,n))continue;
if(chmax(d[Y][X],va-l[y][x]))
que.emplace(d[Y][X],Y,X);
}
}
if(d[n-1][n-1]>0)fin("YES");
fin("NO");
}
cureskol