結果

問題 No.1199 お菓子配り-2
ユーザー ForestedForested
提出日時 2020-08-28 21:24:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 1,399 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 201,116 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-26 14:13:54
合計ジャッジ時間 10,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 38 ms
6,944 KB
testcase_04 AC 83 ms
8,192 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 41 ms
6,940 KB
testcase_08 AC 57 ms
6,940 KB
testcase_09 AC 35 ms
6,940 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 27 ms
6,940 KB
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 10 ms
6,944 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 58 ms
6,940 KB
testcase_17 AC 28 ms
6,940 KB
testcase_18 AC 60 ms
6,944 KB
testcase_19 AC 16 ms
6,940 KB
testcase_20 AC 103 ms
9,600 KB
testcase_21 AC 61 ms
7,040 KB
testcase_22 AC 34 ms
6,940 KB
testcase_23 AC 48 ms
6,944 KB
testcase_24 AC 63 ms
7,040 KB
testcase_25 AC 11 ms
6,940 KB
testcase_26 AC 75 ms
7,424 KB
testcase_27 AC 63 ms
6,944 KB
testcase_28 AC 141 ms
11,392 KB
testcase_29 AC 141 ms
11,392 KB
testcase_30 AC 139 ms
11,264 KB
testcase_31 AC 139 ms
11,392 KB
testcase_32 AC 141 ms
11,392 KB
testcase_33 AC 143 ms
11,520 KB
testcase_34 AC 142 ms
11,264 KB
testcase_35 AC 143 ms
11,392 KB
testcase_36 AC 142 ms
11,520 KB
testcase_37 AC 142 ms
11,392 KB
testcase_38 AC 143 ms
11,392 KB
testcase_39 AC 143 ms
11,520 KB
testcase_40 AC 141 ms
11,264 KB
testcase_41 AC 140 ms
11,264 KB
testcase_42 AC 138 ms
11,392 KB
testcase_43 AC 141 ms
11,520 KB
testcase_44 AC 140 ms
11,392 KB
testcase_45 AC 140 ms
11,392 KB
testcase_46 AC 139 ms
11,392 KB
testcase_47 AC 139 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    rep(i, n) rep(j, m) cin >> a[i][j];
    
    vector<ll> b(n, 0);
    rep(i, n) rep(j, m) b[i] += a[i][j];
    
    vector<vector<ll>> dp(n + 1, vector<ll>(2, -INF));
    dp[0][0] = 0;
    rep(i, n) rep(j, 2) {
        if (dp[i][j] == -INF) continue;
        chmax(dp[i + 1][j], dp[i][j]);
        if (j & 1) {
            chmax(dp[i + 1][0], dp[i][j] - b[i]);
        } else {
            chmax(dp[i + 1][1], dp[i][j] + b[i]);
        }
    }
    
    cout << max(dp[n][0], dp[n][1]) << "\n";
    return 0;
}
0