結果

問題 No.1199 お菓子配り-2
ユーザー MisterMister
提出日時 2020-08-28 22:00:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 1,000 ms
コード長 674 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 75,404 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 14:51:02
合計ジャッジ時間 8,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 34 ms
6,940 KB
testcase_04 AC 83 ms
6,944 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 40 ms
6,940 KB
testcase_08 AC 54 ms
6,944 KB
testcase_09 AC 35 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 27 ms
6,940 KB
testcase_12 AC 27 ms
6,944 KB
testcase_13 AC 10 ms
6,944 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 54 ms
6,940 KB
testcase_17 AC 27 ms
6,940 KB
testcase_18 AC 57 ms
6,940 KB
testcase_19 AC 16 ms
6,940 KB
testcase_20 AC 101 ms
6,940 KB
testcase_21 AC 63 ms
6,940 KB
testcase_22 AC 34 ms
6,944 KB
testcase_23 AC 48 ms
6,940 KB
testcase_24 AC 65 ms
6,940 KB
testcase_25 AC 12 ms
6,940 KB
testcase_26 AC 72 ms
6,944 KB
testcase_27 AC 58 ms
6,940 KB
testcase_28 AC 136 ms
6,940 KB
testcase_29 AC 133 ms
6,940 KB
testcase_30 AC 134 ms
6,940 KB
testcase_31 AC 129 ms
6,940 KB
testcase_32 AC 136 ms
6,944 KB
testcase_33 AC 133 ms
6,944 KB
testcase_34 AC 131 ms
6,940 KB
testcase_35 AC 132 ms
6,940 KB
testcase_36 AC 132 ms
6,940 KB
testcase_37 AC 133 ms
6,944 KB
testcase_38 AC 128 ms
6,940 KB
testcase_39 AC 132 ms
6,944 KB
testcase_40 AC 135 ms
6,944 KB
testcase_41 AC 130 ms
6,940 KB
testcase_42 AC 133 ms
6,940 KB
testcase_43 AC 133 ms
6,940 KB
testcase_44 AC 136 ms
6,940 KB
testcase_45 AC 134 ms
6,944 KB
testcase_46 AC 131 ms
6,940 KB
testcase_47 AC 130 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<lint> dp(2, -INF);
    dp[0] = 0;

    while (n--) {
        lint sum = 0;
        for (int i = 0; i < m; ++i) {
            lint x;
            std::cin >> x;
            sum += x;
        }

        auto ndp = dp;
        ndp[0] = std::max(ndp[0], dp[1] - sum);
        ndp[1] = std::max(ndp[1], dp[0] + sum);
        std::swap(dp, ndp);
    }

    std::cout << std::max(dp[0], dp[1]) << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0