結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー karinohitokarinohito
提出日時 2022-05-21 00:59:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 210,400 KB
実行使用メモリ 18,848 KB
最終ジャッジ日時 2023-10-20 15:21:51
合計ジャッジ時間 5,155 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 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 76 ms
18,848 KB
testcase_08 AC 123 ms
18,848 KB
testcase_09 AC 125 ms
18,848 KB
testcase_10 AC 123 ms
18,848 KB
testcase_11 AC 119 ms
18,848 KB
testcase_12 AC 93 ms
18,848 KB
testcase_13 AC 93 ms
18,848 KB
testcase_14 AC 97 ms
18,848 KB
testcase_15 AC 96 ms
18,848 KB
testcase_16 AC 3 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 93 ms
18,848 KB
testcase_21 AC 95 ms
18,848 KB
testcase_22 AC 83 ms
18,848 KB
testcase_23 AC 82 ms
18,848 KB
testcase_24 AC 80 ms
18,848 KB
testcase_25 AC 113 ms
18,320 KB
testcase_26 AC 115 ms
18,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


int main() {

    ll H, W;
    cin >> H >> W;
    vvll A(H, vll(W));
    rep(h, H)rep(w, W) {
        cin >> A[h][w];
    }

    vvvll DP(H, vvll(W, vll(2, -1e18)));
    DP[0][0][0] = DP[0][0][1] = A[0][0];

    vll dx = { 1,0 };
    vll dy = { 0,1 };
    rep(h, H) {
        rep(w, W) {
            rep(d, 2) {
                ll ny = h + dy[d];
                ll nx = w + dx[d];
                if (ny < 0 || ny >= H || nx < 0 || nx >= W)continue;
                rep(k, 1) {
                    if(ny!=H-1||nx!=W-1)chmax(DP[ny][nx][k + 1], DP[h][w][k]);
                }
                rep(k, 2) {
                    if (A[ny][nx] < DP[h][w][k]) {
                        chmax(DP[ny][nx][k], DP[h][w][k] + A[ny][nx]);
                    }
                }

            }
        }
    }

    bool C = false;
    rep(i, 2) {
        if (DP[H - 1][W - 1][i] >= 0)C = 1;
    }
    cout << (C ? "Yes" : "No") << endl;


}
0