結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-05-20 23:14:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 175,452 KB
実行使用メモリ 19,360 KB
最終ジャッジ日時 2023-10-20 14:06:49
合計ジャッジ時間 4,576 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 74 ms
19,360 KB
testcase_08 AC 128 ms
19,360 KB
testcase_09 AC 129 ms
19,360 KB
testcase_10 AC 130 ms
19,360 KB
testcase_11 AC 129 ms
19,268 KB
testcase_12 AC 100 ms
19,360 KB
testcase_13 AC 99 ms
19,360 KB
testcase_14 AC 99 ms
19,360 KB
testcase_15 AC 98 ms
19,360 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 98 ms
19,360 KB
testcase_21 AC 97 ms
19,260 KB
testcase_22 AC 83 ms
19,360 KB
testcase_23 AC 83 ms
19,360 KB
testcase_24 AC 84 ms
19,360 KB
testcase_25 AC 116 ms
18,740 KB
testcase_26 AC 122 ms
19,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.05.20 23:14:40
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


int main() {
    int h,w;cin >> h >> w;
    vector<vector<vector<ll>>> dp(h,vector<vector<ll>>(w,vector<ll>(2,-1)));
    vector<vector<ll>> a(h,vector<ll>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    dp[0][0][0] = a[0][0];
    dp[0][0][1] = a[0][0];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (dp[i][j][0] != -1) {
                if (j+1 < w) {
                    if (dp[i][j][0] > a[i][j+1]) dp[i][j+1][0] = max(dp[i][j+1][0],dp[i][j][0] + a[i][j+1]);
                    if (i != h-1 || j+1 != w-1) dp[i][j+1][1] = max(dp[i][j+1][1],dp[i][j][0]);
                }
                if (i+1 < h) {
                    if (dp[i][j][0] > a[i+1][j]) dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][0] + a[i+1][j]);
                    if (i+1 != h-1 || j != w-1) dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][0]);
                }
            }
            if (dp[i][j][1] != -1) {
                if (j+1 < w && dp[i][j][1] > a[i][j+1]) {
                    dp[i][j+1][1] = max(dp[i][j+1][1],dp[i][j][1] + a[i][j+1]);
                }
                if (i+1 < h && dp[i][j][1] > a[i+1][j]) {
                    dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][1] + a[i+1][j]);
                }
            }
        }
    }
    if (dp[h-1][w-1][0] != -1 || dp[h-1][w-1][1] != -1) {
        puts("Yes");
    }
    else {
        puts("No");
    }
    return 0;
}
0