結果

問題 No.844 split game
ユーザー kk
提出日時 2021-01-25 22:35:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 202,388 KB
実行使用メモリ 9,288 KB
最終ジャッジ日時 2023-09-04 21:39:32
合計ジャッジ時間 5,884 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
7,012 KB
testcase_01 AC 17 ms
8,160 KB
testcase_02 AC 37 ms
8,052 KB
testcase_03 AC 29 ms
8,296 KB
testcase_04 AC 16 ms
7,000 KB
testcase_05 AC 42 ms
8,728 KB
testcase_06 AC 15 ms
6,960 KB
testcase_07 AC 13 ms
7,440 KB
testcase_08 AC 9 ms
6,672 KB
testcase_09 AC 29 ms
7,192 KB
testcase_10 AC 44 ms
8,468 KB
testcase_11 AC 43 ms
9,120 KB
testcase_12 AC 28 ms
7,032 KB
testcase_13 AC 19 ms
6,548 KB
testcase_14 AC 20 ms
7,660 KB
testcase_15 AC 46 ms
9,288 KB
testcase_16 AC 46 ms
9,288 KB
testcase_17 AC 46 ms
9,288 KB
testcase_18 AC 46 ms
9,216 KB
testcase_19 AC 47 ms
9,288 KB
testcase_20 AC 46 ms
9,284 KB
testcase_21 AC 46 ms
9,280 KB
testcase_22 AC 47 ms
9,236 KB
testcase_23 AC 5 ms
5,888 KB
testcase_24 AC 6 ms
6,172 KB
testcase_25 AC 5 ms
5,844 KB
testcase_26 AC 5 ms
6,108 KB
testcase_27 AC 5 ms
5,980 KB
testcase_28 AC 4 ms
5,928 KB
testcase_29 AC 6 ms
6,104 KB
testcase_30 AC 6 ms
6,060 KB
testcase_31 AC 6 ms
6,020 KB
testcase_32 AC 5 ms
5,972 KB
testcase_33 AC 7 ms
5,868 KB
testcase_34 AC 5 ms
5,944 KB
testcase_35 AC 7 ms
6,140 KB
testcase_36 AC 6 ms
5,792 KB
testcase_37 AC 9 ms
6,040 KB
testcase_38 AC 15 ms
6,564 KB
testcase_39 AC 27 ms
7,424 KB
testcase_40 AC 12 ms
7,040 KB
testcase_41 AC 4 ms
5,728 KB
testcase_42 AC 4 ms
5,740 KB
testcase_43 AC 3 ms
5,772 KB
testcase_44 AC 3 ms
5,852 KB
testcase_45 AC 3 ms
5,684 KB
testcase_46 AC 4 ms
5,852 KB
testcase_47 AC 4 ms
5,668 KB
testcase_48 AC 4 ms
5,848 KB
testcase_49 AC 4 ms
5,816 KB
testcase_50 AC 3 ms
5,672 KB
testcase_51 AC 4 ms
5,736 KB
testcase_52 AC 3 ms
5,688 KB
testcase_53 AC 4 ms
5,800 KB
testcase_54 AC 4 ms
5,800 KB
testcase_55 AC 4 ms
5,672 KB
testcase_56 AC 3 ms
5,740 KB
testcase_57 AC 3 ms
5,740 KB
testcase_58 AC 3 ms
5,728 KB
testcase_59 AC 3 ms
5,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long INF = 1LL<<60;
long long dp[100000+1][2];
vector<pair<int, int> > v[100000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, a;
  cin >> n >> m >> a;

  for (int i = 0; i < m; i++) {
    int l, r, p;
    cin >> l >> r >> p;
    v[r].emplace_back(--l, p);
  }

  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 2; j++)
      dp[i][j] = -INF;
  
  dp[0][0] = dp[0][1] = 0;

  for (int i = 1; i <= n; i++) {
    dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
    for (auto &[l, p]: v[i]) {
      if (dp[l][1] != -INF)
        dp[i][1] = max(dp[i][1], dp[l][1] + p - (i == n ? 0 : a));
      dp[i][1] = max(dp[i][1], dp[l][0] + p - (i == n ? a : 2 * a));
    }
  }

  cout << max(dp[n][0], dp[n][1]) << endl;

  return 0;
}
0