結果
問題 | No.1948 足し算するだけのパズルゲーム(1) |
ユーザー |
![]() |
提出日時 | 2022-05-01 23:38:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,358 bytes |
コンパイル時間 | 1,001 ms |
コンパイル使用メモリ | 79,868 KB |
最終ジャッジ日時 | 2025-01-29 01:25:57 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 5 |
ソースコード
#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"; }