結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー CleyLCleyL
提出日時 2023-06-30 16:53:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 80,080 KB
実行使用メモリ 9,440 KB
最終ジャッジ日時 2023-09-21 10:27:04
合計ジャッジ時間 5,821 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 55 ms
9,340 KB
testcase_08 AC 106 ms
9,320 KB
testcase_09 AC 106 ms
9,432 KB
testcase_10 AC 106 ms
9,296 KB
testcase_11 AC 105 ms
9,292 KB
testcase_12 AC 77 ms
9,312 KB
testcase_13 AC 77 ms
9,440 KB
testcase_14 AC 78 ms
9,300 KB
testcase_15 AC 78 ms
9,436 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
5,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 76 ms
9,316 KB
testcase_21 AC 75 ms
9,264 KB
testcase_22 AC 63 ms
9,316 KB
testcase_23 AC 64 ms
9,312 KB
testcase_24 AC 62 ms
9,316 KB
testcase_25 AC 93 ms
9,436 KB
testcase_26 AC 98 ms
9,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct st{
  int h,w;
  int a;
  bool re;
};

long long dp[510][510][2];

int main(){
  int h,w;cin>>h>>w;
  vector<vector<long long>> A(h,vector<long long>(w));
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>A[i][j];
      dp[i][j][0] = dp[i][j][1] = -1;
    }
  }
  dp[0][0][0] = A[0][0];
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      if(i){
        if(A[i][j] >= dp[i-1][j][0]){
          if(A[i][j] < dp[i-1][j][1]){
            dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][1]+A[i][j]);
          }
          if(!(i+1 == h && j+1 == w)){
            dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][0]);
          }
        }else{
          if(dp[i-1][j][1] != -1)dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][1]+A[i][j]);
          dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][0]+A[i][j]);
        }
      }
      if(j){
        if(A[i][j] >= dp[i][j-1][0]){
          if(A[i][j] < dp[i][j-1][1]){
            dp[i][j][1] = max(dp[i][j][1], dp[i][j-1][1]+A[i][j]);
          }
          if(!(i+1 == h && j+1 == w)){
            dp[i][j][1] = max(dp[i][j][1], dp[i][j-1][0]);
          }
        }else{
          if(dp[i][j-1][1] != -1)dp[i][j][1] = max(dp[i][j][1], dp[i][j-1][1]+A[i][j]);
          dp[i][j][0] = max(dp[i][j][0], dp[i][j-1][0]+A[i][j]);
        }
      }
    }
  }
  cout << (dp[h-1][w-1][0] != -1 || dp[h-1][w-1][1] != -1 ? "Yes" : "No") << endl;
}
0