結果

問題 No.20 砂漠のオアシス
ユーザー AuroraAurora
提出日時 2022-05-10 21:33:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 179,576 KB
実行使用メモリ 5,436 KB
最終ジャッジ日時 2023-09-25 05:10:05
合計ジャッジ時間 3,036 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  int N,V,OX,OY;
  cin >> N >> V >> OX >> OY;
  OX--;
  OY--;
  swap(OX,OY);
  vector<vector<int>> L(N,vector<int>(N));
  for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin >> L[i][j];
  vector<vector<vector<int>>> dp(N,vector<vector<int>>(N,vector<int>(2,-1000000000)));
  dp[0][0][0] = V;
  vector<int> dx = {1,-1,0,0};
  vector<int> dy = {0,0,1,-1};
  priority_queue<pair<int,pair<pair<int,int>,int>>,vector<pair<int,pair<pair<int,int>,int>>>,less<pair<int,pair<pair<int,int>,int>>>> que;
  que.push(make_pair(V,make_pair(make_pair(0,0),0)));
  while(!que.empty()){
    int x = que.top().second.first.first;
    int y = que.top().second.first.second;
    int o = que.top().second.second;
    int H = que.top().first;
    que.pop();
    if(H < dp[x][y][o]) continue;
    for(int i=0;i<4;i++){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
      if(H-L[nx][ny] <= 0) continue;
      int NH = H-L[nx][ny];
      if(dp[nx][ny][o] < NH){
        dp[nx][ny][o] = NH;
        que.push(make_pair(NH,make_pair(make_pair(nx,ny),o)));
      }
      if(o == 0 && OX == nx && OY == ny){
        NH *= 2;
        dp[nx][ny][1] = NH;
        que.push(make_pair(NH,make_pair(make_pair(nx,ny),1)));
      }
    }
  }
  if(dp[N-1][N-1][0] > 0 || dp[N-1][N-1][1] > 0)  cout << "YES" << endl;
  else cout << "NO" << endl;
}
0