結果

問題 No.1199 お菓子配り-2
ユーザー t33ft33f
提出日時 2020-08-28 22:31:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 1,000 ms
コード長 553 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 65,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 15:01:55
合計ジャッジ時間 15,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 104 ms
5,376 KB
testcase_04 AC 250 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 15 ms
5,376 KB
testcase_07 AC 122 ms
5,376 KB
testcase_08 AC 165 ms
5,376 KB
testcase_09 AC 103 ms
5,376 KB
testcase_10 AC 27 ms
5,376 KB
testcase_11 AC 77 ms
5,376 KB
testcase_12 AC 77 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 157 ms
5,376 KB
testcase_17 AC 76 ms
5,376 KB
testcase_18 AC 163 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 300 ms
5,376 KB
testcase_21 AC 186 ms
5,376 KB
testcase_22 AC 106 ms
5,376 KB
testcase_23 AC 134 ms
5,376 KB
testcase_24 AC 178 ms
5,376 KB
testcase_25 AC 28 ms
5,376 KB
testcase_26 AC 223 ms
5,376 KB
testcase_27 AC 165 ms
5,376 KB
testcase_28 AC 397 ms
5,376 KB
testcase_29 AC 401 ms
5,376 KB
testcase_30 AC 397 ms
5,376 KB
testcase_31 AC 387 ms
5,376 KB
testcase_32 AC 410 ms
5,376 KB
testcase_33 AC 403 ms
5,376 KB
testcase_34 AC 403 ms
5,376 KB
testcase_35 AC 395 ms
5,376 KB
testcase_36 AC 399 ms
5,376 KB
testcase_37 AC 410 ms
5,376 KB
testcase_38 AC 410 ms
5,376 KB
testcase_39 AC 404 ms
5,376 KB
testcase_40 AC 419 ms
5,376 KB
testcase_41 AC 406 ms
5,376 KB
testcase_42 AC 402 ms
5,376 KB
testcase_43 AC 426 ms
5,376 KB
testcase_44 AC 416 ms
5,376 KB
testcase_45 AC 413 ms
5,376 KB
testcase_46 AC 403 ms
5,376 KB
testcase_47 AC 392 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:15:19: warning: '*a[0]' may be used uninitialized [-Wmaybe-uninitialized]
   15 |     dp[1][0] = a[0];
      |                ~~~^

ソースコード

diff #

#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    long long a[n];
    for (int i = 0; i < n; i++) {
        long long s = 0;
        for (int j = 0; j < m; j++) {
            long long x; cin >> x;
            s += x;
        }
        a[i] = s;
    }
    long long dp[2][n];
    dp[1][0] = a[0];
    dp[0][0] = 0;
    for (int i = 1; i < n; i++) {
        dp[0][i] = max(dp[0][i-1], dp[1][i-1] - a[i]);
        dp[1][i] = max(dp[1][i-1], dp[0][i-1] + a[i]);
    }
    cout << max(dp[0][n-1], dp[1][n-1]) << endl;
}
0