結果

問題 No.1199 お菓子配り-2
ユーザー Atomic67Atomic67
提出日時 2020-09-11 18:39:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 1,445 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 169,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 03:12:46
合計ジャッジ時間 9,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 32 ms
4,380 KB
testcase_04 AC 79 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 39 ms
4,384 KB
testcase_08 AC 53 ms
4,380 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 9 ms
4,384 KB
testcase_11 AC 26 ms
4,384 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 52 ms
4,384 KB
testcase_17 AC 25 ms
4,384 KB
testcase_18 AC 54 ms
4,380 KB
testcase_19 AC 15 ms
4,384 KB
testcase_20 AC 95 ms
4,380 KB
testcase_21 AC 58 ms
4,384 KB
testcase_22 AC 31 ms
4,380 KB
testcase_23 AC 44 ms
4,384 KB
testcase_24 AC 60 ms
4,384 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 68 ms
4,380 KB
testcase_27 AC 55 ms
4,380 KB
testcase_28 AC 124 ms
4,384 KB
testcase_29 AC 125 ms
4,384 KB
testcase_30 AC 124 ms
4,384 KB
testcase_31 AC 125 ms
4,384 KB
testcase_32 AC 124 ms
4,380 KB
testcase_33 AC 125 ms
4,384 KB
testcase_34 AC 124 ms
4,384 KB
testcase_35 AC 125 ms
4,384 KB
testcase_36 AC 124 ms
4,380 KB
testcase_37 AC 124 ms
4,380 KB
testcase_38 AC 124 ms
4,384 KB
testcase_39 AC 124 ms
4,384 KB
testcase_40 AC 125 ms
4,380 KB
testcase_41 AC 124 ms
4,380 KB
testcase_42 AC 124 ms
4,380 KB
testcase_43 AC 124 ms
4,384 KB
testcase_44 AC 124 ms
4,384 KB
testcase_45 AC 124 ms
4,380 KB
testcase_46 AC 125 ms
4,384 KB
testcase_47 AC 126 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<ll> a(n);
    rep(i, n) {
        ll t = 0;
        rep(j, m) {
            ll ac;
            cin >> ac;
            t += ac;
        }
        a[i] = t;
    }

    vector<vector<ll>> dp(n, vector<ll>(2));
    dp[0][0] = a[0];
    dp[0][1] = 0;

    for(int i = 0; i < n - 1; ++i) {
        dp[i+1][0] = max(dp[i][1] + a[i+1], dp[i][0]);
        dp[i+1][1] = max(dp[i][0] - a[i+1], dp[i][1]);
    }

    cout << max(dp[n-1][0], dp[n-1][1]) << endl;
    return 0;
}
0