結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー rogi52rogi52
提出日時 2022-05-20 22:42:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,373 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 214,936 KB
実行使用メモリ 598,892 KB
最終ジャッジ日時 2023-10-20 13:30:13
合計ジャッジ時間 7,186 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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];

    vector<vector<int>> G(H * W);
    auto h = [&](int i, int j){ return i * W + j; };
    auto h_inv = [&](int v){ return pair<int,int>{v / W, v % W}; };
    rep(i,H)rep(j,W) {
        if(i + 1 < H) G[h(i, j)].push_back(h(i + 1, j));
        if(j + 1 < W) G[h(i, j)].push_back(h(i, j + 1));
    }
    
    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();
        for(int to : G[from]) {
            auto [i, j] = h_inv(to);
            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