結果

問題 No.844 split game
ユーザー MisterMister
提出日時 2020-04-27 18:29:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-05-01 20:08:52
合計ジャッジ時間 4,093 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,760 KB
testcase_01 AC 15 ms
8,448 KB
testcase_02 AC 32 ms
7,296 KB
testcase_03 AC 25 ms
8,448 KB
testcase_04 AC 13 ms
5,504 KB
testcase_05 AC 34 ms
9,088 KB
testcase_06 AC 12 ms
5,504 KB
testcase_07 AC 11 ms
7,296 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 25 ms
5,760 KB
testcase_10 AC 37 ms
8,576 KB
testcase_11 AC 35 ms
9,984 KB
testcase_12 AC 24 ms
5,888 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 17 ms
7,168 KB
testcase_15 AC 40 ms
10,496 KB
testcase_16 AC 40 ms
10,368 KB
testcase_17 AC 40 ms
10,368 KB
testcase_18 AC 39 ms
10,368 KB
testcase_19 AC 40 ms
10,496 KB
testcase_20 AC 41 ms
10,368 KB
testcase_21 AC 41 ms
10,368 KB
testcase_22 AC 38 ms
10,368 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 7 ms
5,376 KB
testcase_38 AC 11 ms
5,376 KB
testcase_39 AC 23 ms
5,888 KB
testcase_40 AC 9 ms
6,144 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 1 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n, m;
    lint a;
    std::cin >> n >> m >> a;

    std::vector<std::vector<std::pair<int, lint>>> rs(n);
    while (m--) {
        int l, r;
        lint p;
        std::cin >> l >> r >> p;
        --l, --r;
        rs[l].emplace_back(r, p);
    }

    auto dp = vec(2, vec(n + 1, -INF));
    dp[1][0] = 0;
    for (int l = 0; l < n; ++l) {
        for (auto [r, p] : rs[l]) {
            for (int i = 0; i < 2; ++i) {
                dp[1][r + 1] = std::max(dp[1][r + 1],
                                        dp[i][l] + p - a * (2 - i));
            }
        }

        for (int i = 0; i < 2; ++i) {
            dp[0][l + 1] = std::max(dp[0][l + 1], dp[i][l]);
        }
    }

    std::cout << std::max(dp[0][n], dp[1][n] + a) << std::endl;
}

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

    solve();

    return 0;
}
0