結果

問題 No.1199 お菓子配り-2
ユーザー MisterMister
提出日時 2020-08-28 22:00:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 1,000 ms
コード長 674 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 73,368 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 22:41:01
合計ジャッジ時間 7,495 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 28 ms
4,380 KB
testcase_04 AC 68 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 33 ms
4,380 KB
testcase_08 AC 45 ms
4,380 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 21 ms
4,376 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 46 ms
4,380 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 46 ms
4,384 KB
testcase_19 AC 13 ms
4,376 KB
testcase_20 AC 80 ms
4,380 KB
testcase_21 AC 50 ms
4,380 KB
testcase_22 AC 27 ms
4,376 KB
testcase_23 AC 37 ms
4,376 KB
testcase_24 AC 52 ms
4,376 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 62 ms
4,384 KB
testcase_27 AC 47 ms
4,376 KB
testcase_28 AC 110 ms
4,384 KB
testcase_29 AC 106 ms
4,380 KB
testcase_30 AC 106 ms
4,380 KB
testcase_31 AC 107 ms
4,380 KB
testcase_32 AC 108 ms
4,380 KB
testcase_33 AC 110 ms
4,380 KB
testcase_34 AC 107 ms
4,376 KB
testcase_35 AC 108 ms
4,380 KB
testcase_36 AC 108 ms
4,380 KB
testcase_37 AC 118 ms
4,384 KB
testcase_38 AC 108 ms
4,380 KB
testcase_39 AC 110 ms
4,380 KB
testcase_40 AC 109 ms
4,376 KB
testcase_41 AC 107 ms
4,380 KB
testcase_42 AC 108 ms
4,380 KB
testcase_43 AC 112 ms
4,380 KB
testcase_44 AC 109 ms
4,380 KB
testcase_45 AC 113 ms
4,380 KB
testcase_46 AC 114 ms
4,376 KB
testcase_47 AC 113 ms
4,384 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