結果

問題 No.1199 お菓子配り-2
ユーザー f_stshf_stsh
提出日時 2020-08-28 21:55:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 1,000 ms
コード長 886 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 165,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 14:49:50
合計ジャッジ時間 16,913 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 107 ms
5,376 KB
testcase_04 AC 272 ms
5,376 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 133 ms
5,376 KB
testcase_08 AC 180 ms
5,376 KB
testcase_09 AC 111 ms
5,376 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 79 ms
5,376 KB
testcase_12 AC 81 ms
5,376 KB
testcase_13 AC 28 ms
5,376 KB
testcase_14 AC 23 ms
5,376 KB
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 169 ms
5,376 KB
testcase_17 AC 85 ms
5,376 KB
testcase_18 AC 177 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 311 ms
5,376 KB
testcase_21 AC 193 ms
5,376 KB
testcase_22 AC 102 ms
5,376 KB
testcase_23 AC 149 ms
5,376 KB
testcase_24 AC 204 ms
5,376 KB
testcase_25 AC 31 ms
5,376 KB
testcase_26 AC 228 ms
5,376 KB
testcase_27 AC 183 ms
5,376 KB
testcase_28 AC 430 ms
5,376 KB
testcase_29 AC 430 ms
5,376 KB
testcase_30 AC 433 ms
5,376 KB
testcase_31 AC 412 ms
5,376 KB
testcase_32 AC 405 ms
5,376 KB
testcase_33 AC 405 ms
5,376 KB
testcase_34 AC 421 ms
5,376 KB
testcase_35 AC 434 ms
5,376 KB
testcase_36 AC 433 ms
5,376 KB
testcase_37 AC 431 ms
5,376 KB
testcase_38 AC 426 ms
5,376 KB
testcase_39 AC 407 ms
5,376 KB
testcase_40 AC 404 ms
5,376 KB
testcase_41 AC 415 ms
5,376 KB
testcase_42 AC 427 ms
5,376 KB
testcase_43 AC 426 ms
5,376 KB
testcase_44 AC 429 ms
5,376 KB
testcase_45 AC 405 ms
5,376 KB
testcase_46 AC 393 ms
5,376 KB
testcase_47 AC 392 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> happinessDegrees(N, 0LL);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            ll hp; cin >> hp;
            happinessDegrees[i] += hp;
        }
    }

    vector<ll> dp(N+1, -LINF);  // N個選んだときのMax
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            dp[j + 1] = max(dp[j + 1], dp[j] + happinessDegrees[i] * (j % 2 ? -1 : 1));
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}
0