結果

問題 No.1199 お菓子配り-2
ユーザー zuminzumin
提出日時 2021-02-26 00:21:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 449 ms / 1,000 ms
コード長 750 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 73,788 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-09 03:18:25
合計ジャッジ時間 22,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 112 ms
6,944 KB
testcase_04 AC 281 ms
10,112 KB
testcase_05 AC 9 ms
6,944 KB
testcase_06 AC 16 ms
6,944 KB
testcase_07 AC 134 ms
6,944 KB
testcase_08 AC 185 ms
6,948 KB
testcase_09 AC 112 ms
6,944 KB
testcase_10 AC 30 ms
6,944 KB
testcase_11 AC 86 ms
6,952 KB
testcase_12 AC 86 ms
6,944 KB
testcase_13 AC 30 ms
6,948 KB
testcase_14 AC 25 ms
6,948 KB
testcase_15 AC 22 ms
6,948 KB
testcase_16 AC 178 ms
6,948 KB
testcase_17 AC 87 ms
6,948 KB
testcase_18 AC 192 ms
9,984 KB
testcase_19 AC 50 ms
6,944 KB
testcase_20 AC 339 ms
9,472 KB
testcase_21 AC 210 ms
11,264 KB
testcase_22 AC 112 ms
9,344 KB
testcase_23 AC 154 ms
9,856 KB
testcase_24 AC 209 ms
9,984 KB
testcase_25 AC 32 ms
6,944 KB
testcase_26 AC 233 ms
6,944 KB
testcase_27 AC 187 ms
6,944 KB
testcase_28 AC 448 ms
11,520 KB
testcase_29 AC 446 ms
11,520 KB
testcase_30 AC 443 ms
11,392 KB
testcase_31 AC 448 ms
11,648 KB
testcase_32 AC 442 ms
11,392 KB
testcase_33 AC 444 ms
11,520 KB
testcase_34 AC 444 ms
11,520 KB
testcase_35 AC 445 ms
11,392 KB
testcase_36 AC 444 ms
11,520 KB
testcase_37 AC 444 ms
11,520 KB
testcase_38 AC 443 ms
11,392 KB
testcase_39 AC 443 ms
11,520 KB
testcase_40 AC 443 ms
11,392 KB
testcase_41 AC 443 ms
11,392 KB
testcase_42 AC 443 ms
11,392 KB
testcase_43 AC 443 ms
11,392 KB
testcase_44 AC 443 ms
11,520 KB
testcase_45 AC 449 ms
11,520 KB
testcase_46 AC 443 ms
11,264 KB
testcase_47 AC 444 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll=long long;

int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,-1e15));
    ll ans=-1e15;
    dp[0][0]=0;



    for(int i=0;i<n;i++){
        ll cur=0;
        for(int j=0;j<m;j++){
            ll tmp;
            cin>>tmp;
            cur+=tmp;
        }
        a.push_back(cur);
    }

    for(int i=0;i<n;i++){
        dp[i+1][0]=0;
        for(int j=1;j<=n;j++){
            if(j%2){
                dp[i+1][j]=max(dp[i][j],dp[i][j-1]+a[i]);
            }else{
                dp[i+1][j]=max(dp[i][j],dp[i][j-1]-a[i]);
            }
            ans=max(ans,dp[i+1][j]);
        }
    }
    cout<<ans<<endl;

    return 0;
}
0