結果

問題 No.1199 お菓子配り-2
ユーザー carrot46carrot46
提出日時 2020-08-28 21:31:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 368 ms / 1,000 ms
コード長 1,073 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 167,052 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-08 22:13:12
合計ジャッジ時間 15,199 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 89 ms
4,380 KB
testcase_04 AC 223 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 13 ms
4,380 KB
testcase_07 AC 105 ms
4,384 KB
testcase_08 AC 144 ms
4,380 KB
testcase_09 AC 88 ms
4,380 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 68 ms
4,376 KB
testcase_12 AC 66 ms
4,380 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 17 ms
4,384 KB
testcase_16 AC 141 ms
4,376 KB
testcase_17 AC 69 ms
4,376 KB
testcase_18 AC 150 ms
4,380 KB
testcase_19 AC 38 ms
4,380 KB
testcase_20 AC 264 ms
4,380 KB
testcase_21 AC 161 ms
4,380 KB
testcase_22 AC 84 ms
4,380 KB
testcase_23 AC 118 ms
4,380 KB
testcase_24 AC 164 ms
4,380 KB
testcase_25 AC 25 ms
4,380 KB
testcase_26 AC 182 ms
4,380 KB
testcase_27 AC 149 ms
4,380 KB
testcase_28 AC 350 ms
4,380 KB
testcase_29 AC 358 ms
4,376 KB
testcase_30 AC 346 ms
4,380 KB
testcase_31 AC 355 ms
4,380 KB
testcase_32 AC 361 ms
4,376 KB
testcase_33 AC 348 ms
4,380 KB
testcase_34 AC 345 ms
4,376 KB
testcase_35 AC 344 ms
4,380 KB
testcase_36 AC 368 ms
4,380 KB
testcase_37 AC 355 ms
4,376 KB
testcase_38 AC 368 ms
4,384 KB
testcase_39 AC 353 ms
4,380 KB
testcase_40 AC 346 ms
4,380 KB
testcase_41 AC 343 ms
4,376 KB
testcase_42 AC 345 ms
4,380 KB
testcase_43 AC 345 ms
4,380 KB
testcase_44 AC 345 ms
4,380 KB
testcase_45 AC 351 ms
4,380 KB
testcase_46 AC 347 ms
4,376 KB
testcase_47 AC 348 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N>>M;
    vec score(N);
    rep(i,N){
        vec temp(M);
        rep(j, M) cin>>temp[j];
        score[i] = accumulate(ALL(temp), 0LL);
    }
    vec dp(2, 0);
    dp[1] = -INF;
    rep(i,N){
        ll temp = max(dp[1], dp[0] + score[i]);
        chmax(dp[0], dp[1] - score[i]);
        chmax(dp[1], temp);
    }
    cout<<max(dp[0], dp[1])<<endl;
}
0