結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー rogi52rogi52
提出日時 2022-05-20 22:47:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,299 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 212,468 KB
実行使用メモリ 529,220 KB
最終ジャッジ日時 2023-10-20 13:37:21
合計ジャッジ時間 6,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 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 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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];

    auto h = [&](int i, int j){ return i * W + j; };
    auto h_inv = [&](int v){ return pair<int,int>{v / W, v % W}; };
    
    vector<vector<ll>> dp(H * W, vector<ll>(2, -1e18));
    queue<int> q;
    q.push(h(0, 0));
    dp[h(0, 0)][0] = dp[h(0, 0)][1] = A[0][0];
    int g = h(H - 1, W - 1);
    while(!q.empty()) {
        int from = q.front(); q.pop();
        auto [ci, cj] = h_inv(from);
        for(int to : {h(ci + 1, cj), h(ci, cj + 1)}) {
            auto [i, j] = h_inv(to);
            if(i == H || j == W) continue;
            int E = A[i][j];
            if(dp[from][0] > E) {
                dp[to][0] = max(dp[to][0], dp[from][0] + E);
            } else {
                if(to != g)
                    dp[to][1] = max(dp[to][1], dp[from][0]);
            }
            if(dp[from][1] > E) {
                dp[to][1] = max(dp[to][1], dp[from][1] + E);
            }
            q.push(to);
        }
    }
    
    cout << (dp[g][0] == -1e18 && dp[g][1] == -1e18 ? "No" : "Yes") << endl;
}
0