結果

問題 No.1199 お菓子配り-2
ユーザー kyoprounokyoprouno
提出日時 2020-08-28 21:53:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 1,000 ms
コード長 1,619 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 176,968 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-26 14:47:52
合計ジャッジ時間 17,473 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 110 ms
6,144 KB
testcase_04 AC 270 ms
9,984 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 128 ms
5,376 KB
testcase_08 AC 176 ms
5,376 KB
testcase_09 AC 106 ms
5,376 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 84 ms
5,376 KB
testcase_12 AC 84 ms
5,376 KB
testcase_13 AC 30 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 176 ms
5,376 KB
testcase_17 AC 85 ms
5,376 KB
testcase_18 AC 183 ms
10,112 KB
testcase_19 AC 47 ms
5,376 KB
testcase_20 AC 326 ms
9,472 KB
testcase_21 AC 205 ms
11,136 KB
testcase_22 AC 109 ms
9,600 KB
testcase_23 AC 147 ms
9,856 KB
testcase_24 AC 202 ms
10,112 KB
testcase_25 AC 30 ms
5,376 KB
testcase_26 AC 228 ms
6,528 KB
testcase_27 AC 183 ms
5,376 KB
testcase_28 AC 426 ms
11,392 KB
testcase_29 AC 427 ms
11,520 KB
testcase_30 AC 432 ms
11,392 KB
testcase_31 AC 427 ms
11,520 KB
testcase_32 AC 434 ms
11,520 KB
testcase_33 AC 436 ms
11,520 KB
testcase_34 AC 433 ms
11,648 KB
testcase_35 AC 431 ms
11,392 KB
testcase_36 AC 428 ms
11,520 KB
testcase_37 AC 429 ms
11,392 KB
testcase_38 AC 428 ms
11,392 KB
testcase_39 AC 427 ms
11,392 KB
testcase_40 AC 427 ms
11,392 KB
testcase_41 AC 425 ms
11,392 KB
testcase_42 AC 431 ms
11,392 KB
testcase_43 AC 428 ms
11,392 KB
testcase_44 AC 422 ms
11,520 KB
testcase_45 AC 428 ms
11,520 KB
testcase_46 AC 432 ms
11,520 KB
testcase_47 AC 424 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e15;

int main(){
    ll n,m;
    cin >> n >> m;
    
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    vector<ll> a(n);
    ll ans=0;
    rep(i,n){
        ll sum=0;
        rep(j,m){
            ll x;
            cin >> x;
            sum+=x;
        }
        a[i]=sum;
    }
    dp[0][0]=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=i;j++){
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if(j%2==1){
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[i-1]);
            }
            else{
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]-a[i-1]);
            }
        }
    }
    for(ll i=0;i<=n;i++){
        ans=max(dp[n][i],ans);
    }
    cout << ans << endl;
    return 0;
}
0