結果

問題 No.2328 Build Walls
ユーザー Ryoga.exeRyoga.exe
提出日時 2023-05-28 15:33:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,071 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 204,084 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2023-08-27 12:24:39
合計ジャッジ時間 6,041 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 70 ms
8,260 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 10 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 61 ms
8,220 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 127 ms
13,040 KB
testcase_29 WA -
testcase_30 AC 135 ms
13,148 KB
testcase_31 AC 134 ms
13,184 KB
testcase_32 WA -
testcase_33 AC 145 ms
13,032 KB
testcase_34 AC 136 ms
12,984 KB
testcase_35 AC 151 ms
13,140 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF64 = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int h, w;
    cin >> h >> w;
    h -= 2;
    vector a(h, vector(w, 0ll));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            if (a[i][j] == -1) {
                a[i][j] = INF64;
            }
        }
    }
    vector dp(h, vector(w, INF64));
    for (int i = 0; i < h; i++) {
        dp[i][0] = a[i][0];
    }
    for (int j = 0; j < w - 1; j++) {
        for (int i = 0; i < h; i++) {
            for (const auto diff : { -1, 0, 1 }) {
                auto nxt = i + diff;
                if (0 <= nxt && nxt < h) {
                    chmin(dp[nxt][j + 1], a[nxt][j + 1] + dp[i][j]);
                }
            }
        }
    }
    ll ans = INF64;
    for (int i = 0; i < h; i++) {
        chmin(ans, dp[i][w - 1]);
    }
    cout << (ans == INF64 ? -1 : ans) << endl;
    return 0;
}
0