結果

問題 No.20 砂漠のオアシス
ユーザー recososorecososo
提出日時 2020-03-03 13:09:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 172,928 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 23:53:48
合計ジャッジ時間 3,159 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,v,ox,oy;cin >> n >> v >> ox >> oy;
  ox--,oy--;
  vector<vector<int>> a(n,vector<int>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  int dp[n][n][2];
  memset(dp,0,sizeof(dp));
  if(v-a[0][0]<=0){
      cout << "NO" << endl;
      return 0;
  }
  dp[0][0][0]=v-a[0][0];
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  queue<pair<pair<int,int>,int>> q;
  q.push({{0,0},0});
  while(!q.empty()){
    int u=q.front().first.first,v=q.front().first.second,w=q.front().second;
    q.pop();
    for(int i=0;i<4;i++){
      int x=u+dx[i],y=v+dy[i];
      if(x>=0&&x<=n-1&&y>=0&&y<=n-1){
        if(dp[x][y][w]<dp[u][v][w]-a[x][y]){
          dp[x][y][w]=dp[u][v][w]-a[x][y];
          q.push({{x,y},w});
        }
        if(!w&&x==ox&&y==oy){
          if(dp[x][y][1]<(dp[u][v][0]-a[x][y])*2){
            cout << dp[u][v][0] << " " << a[x][y] << endl;
            dp[x][y][1]=(dp[u][v][0]-a[x][y])*2;
            q.push({{x,y},1});
          }
        }
      }
    }
  }
  if(dp[n-1][n-1][0]||dp[n-1][n-1][1]){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}
0