結果

問題 No.1199 お菓子配り-2
ユーザー lorent_kyoprolorent_kyopro
提出日時 2020-08-28 23:33:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 1,000 ms
コード長 1,668 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 200,148 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 15:10:49
合計ジャッジ時間 9,618 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 35 ms
6,944 KB
testcase_04 AC 84 ms
6,940 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 43 ms
6,944 KB
testcase_08 AC 58 ms
6,944 KB
testcase_09 AC 34 ms
6,940 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 27 ms
6,944 KB
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 54 ms
6,940 KB
testcase_17 AC 27 ms
6,944 KB
testcase_18 AC 59 ms
6,944 KB
testcase_19 AC 17 ms
6,940 KB
testcase_20 AC 104 ms
6,944 KB
testcase_21 AC 64 ms
6,940 KB
testcase_22 AC 34 ms
6,944 KB
testcase_23 AC 46 ms
6,940 KB
testcase_24 AC 64 ms
6,944 KB
testcase_25 AC 12 ms
6,944 KB
testcase_26 AC 74 ms
6,940 KB
testcase_27 AC 59 ms
6,940 KB
testcase_28 AC 133 ms
6,940 KB
testcase_29 AC 136 ms
6,940 KB
testcase_30 AC 133 ms
6,940 KB
testcase_31 AC 136 ms
6,944 KB
testcase_32 AC 135 ms
6,944 KB
testcase_33 AC 136 ms
6,944 KB
testcase_34 AC 133 ms
6,944 KB
testcase_35 AC 132 ms
6,944 KB
testcase_36 AC 137 ms
6,940 KB
testcase_37 AC 137 ms
6,940 KB
testcase_38 AC 135 ms
6,944 KB
testcase_39 AC 134 ms
6,940 KB
testcase_40 AC 134 ms
6,940 KB
testcase_41 AC 133 ms
6,944 KB
testcase_42 AC 134 ms
6,940 KB
testcase_43 AC 135 ms
6,940 KB
testcase_44 AC 138 ms
6,940 KB
testcase_45 AC 136 ms
6,944 KB
testcase_46 AC 135 ms
6,940 KB
testcase_47 AC 135 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) {
        rep(j, m) {
            ll x;
            cin >> x;
            a[i] += x;
        }
    }
    const ll inf = 1e18;
    auto dp = make_vec<ll>({n+1, 2}, -inf);
    dp[0][0] = 0;
    rep(i, n) {
        chmax(dp[i+1][0], dp[i][0]);
        chmax(dp[i+1][1], dp[i][1]);
        chmax(dp[i+1][1], dp[i][0] + a[i]);
        chmax(dp[i+1][0], dp[i][1] - a[i]);
    }

    cout << max(dp[n][0], dp[n][1]) << '\n';
}
0