結果

問題 No.844 split game
ユーザー sten_sansten_san
提出日時 2021-02-15 15:04:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 210,996 KB
実行使用メモリ 13,000 KB
最終ジャッジ日時 2023-09-30 08:01:19
合計ジャッジ時間 7,527 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
6,404 KB
testcase_01 AC 23 ms
11,252 KB
testcase_02 AC 39 ms
7,452 KB
testcase_03 AC 36 ms
10,480 KB
testcase_04 AC 17 ms
6,216 KB
testcase_05 AC 47 ms
10,872 KB
testcase_06 AC 16 ms
6,428 KB
testcase_07 AC 19 ms
9,564 KB
testcase_08 AC 10 ms
5,408 KB
testcase_09 AC 29 ms
5,144 KB
testcase_10 AC 47 ms
9,548 KB
testcase_11 AC 49 ms
12,484 KB
testcase_12 AC 27 ms
5,008 KB
testcase_13 AC 18 ms
4,580 KB
testcase_14 AC 25 ms
8,756 KB
testcase_15 AC 55 ms
12,736 KB
testcase_16 AC 56 ms
12,704 KB
testcase_17 AC 54 ms
12,856 KB
testcase_18 AC 57 ms
12,864 KB
testcase_19 AC 54 ms
12,824 KB
testcase_20 AC 53 ms
12,936 KB
testcase_21 AC 53 ms
12,764 KB
testcase_22 AC 54 ms
13,000 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 7 ms
4,376 KB
testcase_38 AC 13 ms
4,380 KB
testcase_39 AC 27 ms
5,876 KB
testcase_40 AC 15 ms
7,844 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,384 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); cout.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

int main() {
    int n, m, a; cin >> n >> m >> a;
    auto range = vec<tuple<int, int>>(uns, n + 1, 0);
    for (int i = 0; i < m; ++i) {
        int l, r, p; cin >> l >> r >> p;
        range[r].emplace_back(l, p);
    }

    auto dp = vec<int64_t>(0, n + 1, 2);
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + -a * (i != n);
        for (auto [l, p] : range[i]) {
            dp[i][1] = max({
                dp[i][1],
                dp[l - 1][1] + p - a * (i != n),
                dp[l - 1][0] + p - a * (l - 1 != 0) - a * (i != n),
            });
        }
    }

    cout << dp[n][1] << endl;
}

0