結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー simansiman
提出日時 2022-05-30 15:11:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 5,788 ms
コンパイル使用メモリ 131,040 KB
実行使用メモリ 9,324 KB
最終ジャッジ日時 2023-10-21 00:21:56
合計ジャッジ時間 8,785 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 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 52 ms
9,324 KB
testcase_08 AC 103 ms
9,324 KB
testcase_09 AC 101 ms
9,324 KB
testcase_10 AC 104 ms
9,324 KB
testcase_11 AC 108 ms
9,288 KB
testcase_12 AC 77 ms
9,324 KB
testcase_13 AC 75 ms
9,324 KB
testcase_14 AC 76 ms
9,324 KB
testcase_15 AC 76 ms
9,324 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 75 ms
9,324 KB
testcase_21 AC 73 ms
9,288 KB
testcase_22 AC 61 ms
9,324 KB
testcase_23 AC 59 ms
9,324 KB
testcase_24 AC 62 ms
9,324 KB
testcase_25 AC 93 ms
9,092 KB
testcase_26 AC 96 ms
9,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int H, W;
  cin >> H >> W;
  ll A[H][W];

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      cin >> A[y][x];
    }
  }

  ll dp[H][W][2];
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = A[0][0];

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      for (int i = 0; i < 2; ++i) {
        if (dp[y][x][i] == 0) continue;

        if (y + 1 < H) {
          if (dp[y][x][i] > A[y + 1][x]) {
            dp[y + 1][x][i] = max(dp[y + 1][x][i], dp[y][x][i] + A[y + 1][x]);
          } else if (i == 0) {
            dp[y + 1][x][i + 1] = max(dp[y + 1][x][i + 1], dp[y][x][i]);
          }
        }
        if (x + 1 < W) {
          if (dp[y][x][i] > A[y][x + 1]) {
            dp[y][x + 1][i] = max(dp[y][x + 1][i], dp[y][x][i] + A[y][x + 1]);
          } else if (i == 0) {
            dp[y][x + 1][i + 1] = max(dp[y][x + 1][i + 1], dp[y][x][i]);
          }
        }
      }
    }
  }

  if (max(dp[H - 1][W - 1][0], dp[H - 1][W - 1][1]) > A[H - 1][W - 1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
0