結果

問題 No.1199 お菓子配り-2
ユーザー KKT89KKT89
提出日時 2020-08-28 21:41:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 1,000 ms
コード長 773 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 102,164 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 14:33:45
合計ジャッジ時間 8,231 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 35 ms
6,940 KB
testcase_04 AC 81 ms
6,940 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 40 ms
6,948 KB
testcase_08 AC 54 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,940 KB
testcase_12 AC 27 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 53 ms
6,944 KB
testcase_17 AC 26 ms
6,940 KB
testcase_18 AC 56 ms
6,944 KB
testcase_19 AC 15 ms
6,940 KB
testcase_20 AC 98 ms
6,940 KB
testcase_21 AC 62 ms
6,940 KB
testcase_22 AC 33 ms
6,940 KB
testcase_23 AC 46 ms
6,944 KB
testcase_24 AC 64 ms
6,940 KB
testcase_25 AC 11 ms
6,944 KB
testcase_26 AC 71 ms
6,944 KB
testcase_27 AC 58 ms
6,944 KB
testcase_28 AC 131 ms
6,940 KB
testcase_29 AC 128 ms
6,944 KB
testcase_30 AC 130 ms
6,940 KB
testcase_31 AC 129 ms
6,940 KB
testcase_32 AC 128 ms
6,944 KB
testcase_33 AC 127 ms
6,944 KB
testcase_34 AC 130 ms
6,944 KB
testcase_35 AC 128 ms
6,944 KB
testcase_36 AC 132 ms
6,944 KB
testcase_37 AC 135 ms
6,940 KB
testcase_38 AC 131 ms
6,940 KB
testcase_39 AC 129 ms
6,940 KB
testcase_40 AC 130 ms
6,940 KB
testcase_41 AC 130 ms
6,940 KB
testcase_42 AC 134 ms
6,944 KB
testcase_43 AC 136 ms
6,944 KB
testcase_44 AC 134 ms
6,944 KB
testcase_45 AC 134 ms
6,944 KB
testcase_46 AC 132 ms
6,940 KB
testcase_47 AC 133 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
using namespace std;
typedef long long int ll;

ll dp[1010][2];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ll x; cin >> x;
            a[i]+=x;
        }
    }
    for(int i=0;i<1010;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=-1e18;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            dp[i+1][j^1]=max(dp[i+1][j^1],dp[i][j]+(j%2==0?1LL:-1LL)*a[i]);
        }
    }
    cout << max(dp[n][0],dp[n][1]) << endl;
}
0