結果

問題 No.1199 お菓子配り-2
ユーザー kyoprounokyoprouno
提出日時 2020-08-28 21:53:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 1,000 ms
コード長 1,619 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 177,516 KB
実行使用メモリ 11,532 KB
最終ジャッジ日時 2023-08-08 22:38:03
合計ジャッジ時間 15,207 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 87 ms
5,872 KB
testcase_04 AC 218 ms
9,940 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 13 ms
4,380 KB
testcase_07 AC 107 ms
4,848 KB
testcase_08 AC 153 ms
5,120 KB
testcase_09 AC 88 ms
4,380 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 70 ms
4,380 KB
testcase_12 AC 67 ms
4,376 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 144 ms
4,796 KB
testcase_17 AC 70 ms
5,152 KB
testcase_18 AC 159 ms
9,848 KB
testcase_19 AC 40 ms
5,128 KB
testcase_20 AC 266 ms
9,308 KB
testcase_21 AC 172 ms
11,020 KB
testcase_22 AC 87 ms
9,240 KB
testcase_23 AC 120 ms
9,708 KB
testcase_24 AC 176 ms
9,904 KB
testcase_25 AC 25 ms
4,380 KB
testcase_26 AC 186 ms
6,332 KB
testcase_27 AC 161 ms
5,036 KB
testcase_28 AC 368 ms
11,232 KB
testcase_29 AC 360 ms
11,208 KB
testcase_30 AC 349 ms
11,260 KB
testcase_31 AC 358 ms
11,220 KB
testcase_32 AC 373 ms
11,228 KB
testcase_33 AC 359 ms
11,280 KB
testcase_34 AC 348 ms
11,296 KB
testcase_35 AC 349 ms
11,208 KB
testcase_36 AC 353 ms
11,316 KB
testcase_37 AC 348 ms
11,228 KB
testcase_38 AC 346 ms
11,356 KB
testcase_39 AC 354 ms
11,288 KB
testcase_40 AC 348 ms
11,532 KB
testcase_41 AC 357 ms
11,280 KB
testcase_42 AC 352 ms
11,240 KB
testcase_43 AC 348 ms
11,232 KB
testcase_44 AC 349 ms
11,240 KB
testcase_45 AC 351 ms
11,208 KB
testcase_46 AC 346 ms
11,224 KB
testcase_47 AC 349 ms
11,224 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