結果

問題 No.844 split game
ユーザー ikdikd
提出日時 2019-06-28 22:28:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 83,612 KB
実行使用メモリ 13,604 KB
最終ジャッジ日時 2023-09-14 22:11:53
合計ジャッジ時間 5,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,744 KB
testcase_01 AC 42 ms
11,160 KB
testcase_02 AC 93 ms
8,412 KB
testcase_03 AC 72 ms
10,952 KB
testcase_04 AC 35 ms
6,532 KB
testcase_05 AC 110 ms
11,420 KB
testcase_06 AC 34 ms
6,800 KB
testcase_07 AC 32 ms
9,640 KB
testcase_08 AC 17 ms
5,448 KB
testcase_09 AC 76 ms
5,900 KB
testcase_10 AC 114 ms
10,720 KB
testcase_11 AC 112 ms
13,068 KB
testcase_12 AC 73 ms
5,736 KB
testcase_13 AC 46 ms
4,920 KB
testcase_14 AC 51 ms
9,116 KB
testcase_15 AC 123 ms
13,284 KB
testcase_16 AC 122 ms
13,604 KB
testcase_17 AC 123 ms
13,328 KB
testcase_18 AC 123 ms
13,288 KB
testcase_19 AC 122 ms
13,456 KB
testcase_20 AC 122 ms
13,468 KB
testcase_21 AC 123 ms
13,472 KB
testcase_22 AC 123 ms
13,468 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 9 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 9 ms
4,380 KB
testcase_34 AC 6 ms
4,376 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 16 ms
4,376 KB
testcase_38 AC 31 ms
4,572 KB
testcase_39 AC 68 ms
6,532 KB
testcase_40 AC 25 ms
8,048 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

void chmax(int64_t &a, int64_t b) {
  if (a < b) a = b;
}

int main () {
  
  int n, m;
  cin >> n >> m;
  int64_t c;
  cin >> c;
  vector<vector<tuple<int, int64_t>>> rights(n + 1);
  rep(i, m) {
    int l, r;
    int64_t p;
    cin >> l >> r >> p;
    rights[r].emplace_back(l - 1, p);
  }
  
  const int64_t inf = 1e18;
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(2, -inf));
  dp[0][1] = 0;
  for (int x = 1; x <= n; x++) {
    chmax(dp[x][0], max(dp[x - 1][0], dp[x - 1][1]));
    for (auto t: rights[x]) {
      int l;
      int64_t p;
      tie(l, p) = t;
      chmax(dp[x][1], dp[l][1] + p - (x < n ? c : 0));
      chmax(dp[x][1], dp[l][0] + p - c - (x < n ? c : 0));
    }
  }
  
  rep(i, n + 1) rep(j, 2) {
    // cout << dp[i][j] << endl;
  }
  cout << max(dp[n][0], dp[n][1]) << endl;

  return 0;
}
0