結果

問題 No.1199 お菓子配り-2
ユーザー KKT89KKT89
提出日時 2020-08-28 21:41:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 773 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 99,988 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-08 22:24:26
合計ジャッジ時間 8,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 32 ms
4,380 KB
testcase_04 AC 77 ms
4,384 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,384 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 53 ms
4,384 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 9 ms
4,384 KB
testcase_11 AC 25 ms
4,380 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,384 KB
testcase_16 AC 51 ms
4,380 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 54 ms
4,384 KB
testcase_19 AC 15 ms
4,384 KB
testcase_20 AC 94 ms
4,384 KB
testcase_21 AC 58 ms
4,384 KB
testcase_22 AC 31 ms
4,380 KB
testcase_23 AC 44 ms
4,380 KB
testcase_24 AC 59 ms
4,380 KB
testcase_25 AC 10 ms
4,384 KB
testcase_26 AC 67 ms
4,380 KB
testcase_27 AC 54 ms
4,380 KB
testcase_28 AC 124 ms
4,380 KB
testcase_29 AC 124 ms
4,380 KB
testcase_30 AC 123 ms
4,384 KB
testcase_31 AC 124 ms
4,380 KB
testcase_32 AC 124 ms
4,380 KB
testcase_33 AC 124 ms
4,380 KB
testcase_34 AC 123 ms
4,380 KB
testcase_35 AC 124 ms
4,380 KB
testcase_36 AC 123 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,380 KB
testcase_40 AC 124 ms
4,380 KB
testcase_41 AC 123 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,388 KB
testcase_46 AC 124 ms
4,384 KB
testcase_47 AC 124 ms
4,380 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