結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー rogi52rogi52
提出日時 2022-05-20 23:14:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 210,088 KB
実行使用メモリ 19,088 KB
最終ジャッジ日時 2023-10-20 14:07:00
合計ジャッジ時間 4,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 2 ms
4,348 KB
testcase_07 AC 43 ms
19,088 KB
testcase_08 AC 55 ms
19,088 KB
testcase_09 AC 55 ms
19,088 KB
testcase_10 AC 54 ms
19,088 KB
testcase_11 AC 54 ms
18,824 KB
testcase_12 AC 47 ms
19,088 KB
testcase_13 AC 46 ms
19,088 KB
testcase_14 AC 48 ms
19,088 KB
testcase_15 AC 46 ms
19,088 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 49 ms
19,088 KB
testcase_21 AC 49 ms
18,824 KB
testcase_22 AC 46 ms
19,088 KB
testcase_23 AC 45 ms
19,088 KB
testcase_24 AC 45 ms
19,088 KB
testcase_25 AC 53 ms
18,296 KB
testcase_26 AC 55 ms
19,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

void chmax(ll &a, ll b){ if(a < b) a = b; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int H,W; cin >> H >> W;
    vector<vector<ll>> A(H, vector<ll>(W));
    rep(i,H)rep(j,W) cin >> A[i][j];

    vector<vector<vector<ll>>> dp(H, vector<vector<ll>>(W, vector<ll>(2, -1e18)));
    dp[0][0][0] = dp[0][0][1] = A[0][0];
    rep(i,H)rep(j,W) {
        if(i + 1 < H) {
            int ni = i + 1, nj = j;
            int E = A[ni][nj];
            if(dp[i][j][0] > E) chmax(dp[ni][nj][0], dp[i][j][0] + E);
            else if(!(ni == H - 1 && nj == W - 1)) chmax(dp[ni][nj][1], dp[i][j][0]);
            if(dp[i][j][1] > E) chmax(dp[ni][nj][1], dp[i][j][1] + E);
        }
        if(j + 1 < W) {
            int ni = i, nj = j + 1;
            int E = A[ni][nj];
            if(dp[i][j][0] > E) chmax(dp[ni][nj][0], dp[i][j][0] + E);
            else if(!(ni == H - 1 && nj == W - 1)) chmax(dp[ni][nj][1], dp[i][j][0]);
            if(dp[i][j][1] > E) chmax(dp[ni][nj][1], dp[i][j][1] + E);
        }
    }
    cout << (dp[H - 1][W - 1][0] == -1e18 && dp[H - 1][W - 1][1] == -1e18 ? "No" : "Yes") << endl;
}
0