結果

問題 No.20 砂漠のオアシス
ユーザー beetbeet
提出日時 2019-04-25 19:30:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 1,738 bytes
コンパイル時間 2,775 ms
コンパイル使用メモリ 216,712 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-13 12:31:02
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,504 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 9 ms
4,456 KB
testcase_07 AC 31 ms
4,380 KB
testcase_08 AC 12 ms
4,464 KB
testcase_09 AC 26 ms
4,424 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0