結果

問題 No.1199 お菓子配り-2
ユーザー yel
提出日時 2023-10-06 21:44:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 425 ms / 1,000 ms
コード長 939 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 172,136 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-07-26 15:55:06
合計ジャッジ時間 18,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
const int MAX = 1e9;
const int MIN = -1*1e9;
const ll MAXLL = 1e18;
const ll MINLL = -1*1e18;
//const ll MOD = 998244353;
//const ll MOD = 1000000007;
int main()
{
    ll N,M; cin >> N >> M;
    vector<ll> V(N);
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            ll A; cin >> A;
            V[i] += A;
        }   
    }

    vector<vector<ll>> DP(N+1,vector<ll>(N+1,MINLL));
    DP[0][0] = 0;

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= i; 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+1)%2==0?-V[i]:V[i]));
        }
    }

    ll Ans = MINLL;
    for(int i = 0; i <= N; i++) Ans = max(Ans,DP[N][i]);

    cout << Ans << endl;
    return 0;
}
0