結果

問題 No.1199 お菓子配り-2
ユーザー maguromaguro
提出日時 2020-08-28 21:58:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 1,000 ms
コード長 1,612 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 196,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 14:50:34
合計ジャッジ時間 18,058 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 112 ms
6,944 KB
testcase_04 AC 436 ms
6,944 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 AC 17 ms
6,940 KB
testcase_07 AC 134 ms
6,944 KB
testcase_08 AC 179 ms
6,944 KB
testcase_09 AC 150 ms
6,940 KB
testcase_10 AC 28 ms
6,944 KB
testcase_11 AC 85 ms
6,944 KB
testcase_12 AC 93 ms
6,944 KB
testcase_13 AC 31 ms
6,944 KB
testcase_14 AC 26 ms
6,944 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 183 ms
6,944 KB
testcase_17 AC 84 ms
6,940 KB
testcase_18 AC 182 ms
6,944 KB
testcase_19 AC 47 ms
6,944 KB
testcase_20 AC 327 ms
6,944 KB
testcase_21 AC 196 ms
6,940 KB
testcase_22 AC 107 ms
6,940 KB
testcase_23 AC 148 ms
6,944 KB
testcase_24 AC 205 ms
6,940 KB
testcase_25 AC 32 ms
6,944 KB
testcase_26 AC 230 ms
6,940 KB
testcase_27 AC 183 ms
6,944 KB
testcase_28 AC 428 ms
6,940 KB
testcase_29 AC 431 ms
6,940 KB
testcase_30 AC 424 ms
6,940 KB
testcase_31 AC 429 ms
6,944 KB
testcase_32 AC 422 ms
6,940 KB
testcase_33 AC 431 ms
6,940 KB
testcase_34 AC 423 ms
6,940 KB
testcase_35 AC 424 ms
6,940 KB
testcase_36 AC 429 ms
6,944 KB
testcase_37 AC 433 ms
6,940 KB
testcase_38 AC 431 ms
6,944 KB
testcase_39 AC 423 ms
6,940 KB
testcase_40 AC 426 ms
6,940 KB
testcase_41 AC 425 ms
6,940 KB
testcase_42 AC 427 ms
6,944 KB
testcase_43 AC 427 ms
6,940 KB
testcase_44 AC 427 ms
6,940 KB
testcase_45 AC 429 ms
6,940 KB
testcase_46 AC 426 ms
6,940 KB
testcase_47 AC 447 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

ll dp[1010][2] = {-INF}; //dp[i][j] = i番目のお菓子まででの幸せ度の最大値、ただしj = 0の時は正、j = 1の時は負

int main() {
    int N,M;
    cin >> N >> M;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        ll cnt = 0;
        for(int j = 0;j < M;j++) {
            ll A;
            cin >> A;
            cnt += A;
        }
        vec.at(i) = cnt;
    }
    dp[0][0] = 0;
    for(int i = 0;i < N;i++) {
        chmax(dp[i + 1][0],dp[i][1] - vec.at(i));
        chmax(dp[i + 1][0],dp[i][0]);
        chmax(dp[i + 1][1],dp[i][0] + vec.at(i));
        chmax(dp[i + 1][1],dp[i][1]);
    }
    cout << max(dp[N][0],dp[N][1]) << endl;
}
0