結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー siman
提出日時 2022-05-30 15:11:20
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 9,694 ms
コンパイル使用メモリ 141,696 KB
実行使用メモリ 9,360 KB
最終ジャッジ日時 2024-09-21 00:52:20
合計ジャッジ時間 5,387 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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