結果

問題 No.1199 お菓子配り-2
ユーザー outlineoutline
提出日時 2021-08-03 16:23:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 1,817 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 138,092 KB
実行使用メモリ 11,564 KB
最終ジャッジ日時 2023-10-14 21:09:01
合計ジャッジ時間 11,900 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 34 ms
5,196 KB
testcase_04 AC 81 ms
8,164 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 6 ms
4,356 KB
testcase_07 AC 40 ms
5,392 KB
testcase_08 AC 56 ms
6,536 KB
testcase_09 AC 34 ms
5,136 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 27 ms
4,688 KB
testcase_12 AC 26 ms
4,680 KB
testcase_13 AC 10 ms
4,352 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 8 ms
4,352 KB
testcase_16 AC 54 ms
6,196 KB
testcase_17 AC 26 ms
4,744 KB
testcase_18 AC 56 ms
6,452 KB
testcase_19 AC 15 ms
4,348 KB
testcase_20 AC 99 ms
9,440 KB
testcase_21 AC 61 ms
7,016 KB
testcase_22 AC 33 ms
5,260 KB
testcase_23 AC 46 ms
5,992 KB
testcase_24 AC 62 ms
6,800 KB
testcase_25 AC 11 ms
4,352 KB
testcase_26 AC 71 ms
7,564 KB
testcase_27 AC 57 ms
6,472 KB
testcase_28 AC 130 ms
11,328 KB
testcase_29 AC 129 ms
11,260 KB
testcase_30 AC 131 ms
11,352 KB
testcase_31 AC 130 ms
11,228 KB
testcase_32 AC 130 ms
11,484 KB
testcase_33 AC 131 ms
11,480 KB
testcase_34 AC 130 ms
11,252 KB
testcase_35 AC 130 ms
11,232 KB
testcase_36 AC 130 ms
11,320 KB
testcase_37 AC 129 ms
11,316 KB
testcase_38 AC 129 ms
11,256 KB
testcase_39 AC 130 ms
11,268 KB
testcase_40 AC 129 ms
11,420 KB
testcase_41 AC 130 ms
11,256 KB
testcase_42 AC 129 ms
11,260 KB
testcase_43 AC 130 ms
11,272 KB
testcase_44 AC 130 ms
11,232 KB
testcase_45 AC 129 ms
11,232 KB
testcase_46 AC 129 ms
11,564 KB
testcase_47 AC 132 ms
11,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector A(N, vector<ll>(M));
    vector<ll> S(N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            cin >> A[i][j];
            S[i] += A[i][j];
        }
    }

    constexpr ll inf = 1e+17;
    vector dp(N + 1, vector<ll>(2, -inf));
    dp[0][0] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 2; ++j){
            if(dp[i][j] == -inf)    continue;
            chmax(dp[i + 1][j], dp[i][j]);
            chmax(dp[i + 1][j ^ 1], dp[i][j] + S[i] * (j ? -1 : 1));
        }
    }

    cout << max(dp[N][0], dp[N][1]) << endl;

    return 0;
}
0