結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー SSRSSSRS
提出日時 2022-05-20 21:39:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 175,496 KB
実行使用メモリ 7,340 KB
最終ジャッジ日時 2023-10-20 12:03:28
合計ジャッジ時間 4,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 59 ms
7,328 KB
testcase_08 AC 115 ms
7,328 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 84 ms
7,328 KB
testcase_13 AC 84 ms
7,328 KB
testcase_14 AC 84 ms
7,328 KB
testcase_15 AC 84 ms
7,328 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 83 ms
7,328 KB
testcase_21 AC 83 ms
7,328 KB
testcase_22 AC 69 ms
7,328 KB
testcase_23 AC 70 ms
7,328 KB
testcase_24 AC 69 ms
7,328 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  vector<vector<vector<int>>> dp(2, vector<vector<int>>(H, vector<int>(W, -1)));
  dp[0][0][0] = A[0][0];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (i < H - 1){
        if (dp[0][i][j] > A[i + 1][j]){
          dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[0][i][j] + A[i + 1][j]);
        }
        if (dp[1][i][j] > A[i + 1][j]){
          dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[1][i][j] + A[i + 1][j]);
        }
        if (!(i == H - 2 && j == W - 1)){
          dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[0][i][j]);
        }
      }
      if (j < W - 1){
        if (dp[0][i][j] > A[i][j + 1]){
          dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j] + A[i][j + 1]);
        }
        if (dp[1][i][j] > A[i][j + 1]){
          dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j] + A[i][j + 1]);
        }
        if (!(i == H - 1 && j == W - 2)){
          dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[0][i][j]);
        }
      }
    }
  }
  if (dp[0][H - 1][W - 1] >= 0 || dp[1][H - 1][W - 1] >= 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
0