結果

問題 No.20 砂漠のオアシス
ユーザー cureskolcureskol
提出日時 2022-05-28 18:51:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,805 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 226,020 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 23:35:17
合計ジャッジ時間 3,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 15 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 14 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 13 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[oy][ox]=v;
  que.emplace(v,oy,ox);
  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");
}
0