結果

問題 No.1948 足し算するだけのパズルゲーム(1)
コンテスト
ユーザー siman
提出日時 2022-05-30 15:11:20
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,337 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,064 ms
コンパイル使用メモリ 149,504 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2026-04-09 09:07:56
合計ジャッジ時間 3,966 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:19:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   19 |   ll A[H][W];
      |           ^
main.cpp:19:11: note: read of non-const variable 'W' is not allowed in a constant expression
main.cpp:17:10: note: declared here
   17 |   int H, W;
      |          ^
main.cpp:19:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   19 |   ll A[H][W];
      |        ^
main.cpp:19:8: note: read of non-const variable 'H' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int H, W;
      |       ^
main.cpp:27:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   27 |   ll dp[H][W][2];
      |            ^
main.cpp:27:12: note: read of non-const variable 'W' is not allowed in a constant expression
main.cpp:17:10: note: declared here
   17 |   int H, W;
      |          ^
main.cpp:27:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   27 |   ll dp[H][W][2];
      |         ^
main.cpp:27:9: note: read of non-const variable 'H' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int H, W;
      |       ^
4 warnings generated.

ソースコード

diff #
raw source code

#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