結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー naskyanaskya
提出日時 2022-05-01 23:38:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,358 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 80,848 KB
実行使用メモリ 6,096 KB
最終ジャッジ日時 2023-09-13 16:28:59
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<int>(W)), dp_l(H, std::vector<int>(W)), dp_f(H, std::vector<int>(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, 0, -1}, dx[] {1, 0, -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