結果

問題 No.844 split game
ユーザー lowrlowr
提出日時 2019-08-16 19:26:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 217,572 KB
実行使用メモリ 10,448 KB
最終ジャッジ日時 2023-10-23 19:00:56
合計ジャッジ時間 9,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
5,976 KB
testcase_01 AC 38 ms
8,888 KB
testcase_02 AC 95 ms
7,016 KB
testcase_03 AC 69 ms
8,616 KB
testcase_04 AC 36 ms
5,712 KB
testcase_05 AC 106 ms
9,128 KB
testcase_06 AC 34 ms
5,720 KB
testcase_07 AC 30 ms
7,832 KB
testcase_08 AC 18 ms
5,064 KB
testcase_09 AC 81 ms
5,432 KB
testcase_10 AC 113 ms
8,336 KB
testcase_11 AC 109 ms
9,920 KB
testcase_12 AC 81 ms
5,396 KB
testcase_13 AC 49 ms
4,656 KB
testcase_14 AC 49 ms
7,560 KB
testcase_15 AC 118 ms
10,448 KB
testcase_16 AC 119 ms
10,448 KB
testcase_17 AC 119 ms
10,448 KB
testcase_18 AC 119 ms
10,448 KB
testcase_19 AC 118 ms
10,448 KB
testcase_20 AC 118 ms
10,448 KB
testcase_21 AC 118 ms
10,448 KB
testcase_22 AC 119 ms
10,448 KB
testcase_23 AC 6 ms
4,372 KB
testcase_24 AC 9 ms
4,372 KB
testcase_25 AC 7 ms
4,372 KB
testcase_26 AC 4 ms
4,372 KB
testcase_27 AC 8 ms
4,372 KB
testcase_28 AC 4 ms
4,372 KB
testcase_29 AC 8 ms
4,372 KB
testcase_30 AC 9 ms
4,372 KB
testcase_31 AC 8 ms
4,372 KB
testcase_32 AC 4 ms
4,372 KB
testcase_33 AC 12 ms
4,372 KB
testcase_34 AC 7 ms
4,372 KB
testcase_35 AC 13 ms
4,372 KB
testcase_36 AC 9 ms
4,372 KB
testcase_37 AC 19 ms
4,372 KB
testcase_38 AC 34 ms
4,392 KB
testcase_39 AC 71 ms
5,696 KB
testcase_40 AC 24 ms
6,512 KB
testcase_41 AC 2 ms
4,372 KB
testcase_42 AC 2 ms
4,372 KB
testcase_43 AC 2 ms
4,372 KB
testcase_44 AC 2 ms
4,372 KB
testcase_45 AC 2 ms
4,372 KB
testcase_46 AC 2 ms
4,372 KB
testcase_47 AC 2 ms
4,372 KB
testcase_48 AC 2 ms
4,372 KB
testcase_49 AC 2 ms
4,372 KB
testcase_50 AC 2 ms
4,372 KB
testcase_51 AC 2 ms
4,372 KB
testcase_52 AC 2 ms
4,372 KB
testcase_53 AC 2 ms
4,372 KB
testcase_54 AC 2 ms
4,372 KB
testcase_55 AC 2 ms
4,372 KB
testcase_56 AC 2 ms
4,372 KB
testcase_57 AC 2 ms
4,372 KB
testcase_58 AC 2 ms
4,372 KB
testcase_59 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;

int main() {
  unsigned n, m;
  i64 a;
  std::cin >> n >> m >> a;
  std::vector<std::pair<std::pair<unsigned, unsigned>, i64>> v;
  for (unsigned i = 0; i < m; i++) {
    int l, r;
    i64 p;
    std::cin >> l >> r >> p;
    v.emplace_back(std::piecewise_construct, std::make_tuple(r, l), std::make_tuple(p));
  }
  std::sort(v.begin(), v.end());

  std::vector<std::vector<i64>> dp(n + 1, std::vector<i64>(2));
  for (unsigned i = 1, j = 0; i <= n; i++) {
    dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = dp[1][0] - a;
    while (j < m && v[j].first.first == i) {
      dp[i][1] = std::max({
            dp[i][1],
            dp[v[j].first.second - 1][0] + v[j].second - a * 2,
            dp[v[j].first.second - 1][1] + v[j].second - a
          });
      j++;
    }
  }

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

  return 0;
}

0