結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー naskyanaskya
提出日時 2022-05-01 23:42:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,362 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 81,072 KB
実行使用メモリ 9,300 KB
最終ジャッジ日時 2023-09-13 16:35:29
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int H, W;
  std::cin >> H >> W;

  std::vector map(H, std::vector<long long>(W)), dp_l(H, std::vector<long long>(W)), dp_f(H, std::vector<long long>(W));
  for (int i = 0; i < H; ++i) {
    std::copy_n(std::istream_iterator<int>(std::cin), W, map[i].begin());
  }

  dp_l[0][0] = map[0][0];

  constexpr int dy[] {0, 1}, dx[] {1, 0};

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      for (int k = 0; k < 4; ++k) {
        const int ni = i + dy[k], nj = j + dx[k];
        if (ni < 0 || H <= ni || nj < 0 || W <= nj) {
          continue;
        }
        if (dp_l[i][j] > map[ni][nj]) {
          if (ni == H - 1 && nj == W - 1) {
            std::cout << "Yes\n";
            return 0;
          }
          dp_l[ni][nj] = std::max(dp_l[ni][nj], dp_l[i][j] + map[ni][nj]);
        } else if (ni != H - 1 || nj != W - 1) {
          dp_f[ni][nj] = std::max(dp_f[ni][nj], dp_l[i][j]);
        }

        if (dp_f[i][j] > map[ni][nj]) {
          if (ni == H - 1 && nj == W - 1) {
            std::cout << "Yes\n";
            return 0;
          }
          dp_f[ni][nj] = std::max(dp_f[ni][nj], dp_f[i][j] + map[ni][nj]);
        }
      }
    }
  }

  std::cout << "No\n";
}
0