結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-05-20 23:12:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 175,400 KB
実行使用メモリ 19,356 KB
最終ジャッジ日時 2023-10-20 14:04:50
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
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 2 ms
4,348 KB
testcase_07 AC 75 ms
19,356 KB
testcase_08 AC 130 ms
19,356 KB
testcase_09 AC 129 ms
19,356 KB
testcase_10 AC 129 ms
19,356 KB
testcase_11 AC 127 ms
19,264 KB
testcase_12 WA -
testcase_13 AC 99 ms
19,356 KB
testcase_14 AC 97 ms
19,356 KB
testcase_15 AC 99 ms
19,356 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,356 KB
testcase_21 AC 97 ms
19,256 KB
testcase_22 AC 85 ms
19,356 KB
testcase_23 AC 85 ms
19,356 KB
testcase_24 AC 84 ms
19,356 KB
testcase_25 AC 118 ms
18,736 KB
testcase_26 AC 123 ms
19,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.05.20 23:12:15
**/

#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]);
                    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]);
                    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][1] != -1) {
        puts("Yes");
    }
    else {
        puts("No");
    }
    return 0;
}
0