結果

問題 No.20 砂漠のオアシス
ユーザー recososorecososo
提出日時 2020-03-03 13:13:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,050 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 172,672 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 23:54:43
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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));
  dp[0][0][0]=v;
  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==oy&&y==ox){
          if(dp[x][y][1]<(dp[u][v][0]-a[x][y])*2){
            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