結果

問題 No.844 split game
ユーザー MayimgMayimg
提出日時 2019-06-30 03:24:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 208,600 KB
実行使用メモリ 13,060 KB
最終ジャッジ日時 2023-09-17 19:11:50
合計ジャッジ時間 6,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
6,420 KB
testcase_01 AC 25 ms
11,260 KB
testcase_02 AC 39 ms
7,616 KB
testcase_03 AC 36 ms
10,428 KB
testcase_04 AC 17 ms
6,248 KB
testcase_05 AC 48 ms
10,960 KB
testcase_06 AC 16 ms
6,440 KB
testcase_07 AC 19 ms
9,684 KB
testcase_08 AC 9 ms
5,368 KB
testcase_09 AC 28 ms
5,212 KB
testcase_10 AC 48 ms
9,596 KB
testcase_11 AC 55 ms
12,276 KB
testcase_12 AC 27 ms
4,800 KB
testcase_13 AC 18 ms
4,552 KB
testcase_14 AC 24 ms
8,772 KB
testcase_15 AC 57 ms
12,996 KB
testcase_16 AC 56 ms
12,808 KB
testcase_17 AC 56 ms
12,736 KB
testcase_18 AC 56 ms
12,724 KB
testcase_19 AC 56 ms
13,060 KB
testcase_20 AC 55 ms
12,872 KB
testcase_21 AC 59 ms
12,828 KB
testcase_22 AC 56 ms
12,892 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 13 ms
4,376 KB
testcase_39 AC 27 ms
5,760 KB
testcase_40 AC 15 ms
7,716 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,384 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0); 
  int n, m, a;
  cin >> n >> m >> a;
  vector<vector<pair<int, int>>> segs(n + 1);
  for (int i = 0; i < m; i++) {
    int l, r, p;
    cin >> l >> r >> p;
    segs[r].emplace_back(l - 1, p);
  }
  auto dp = vector<vector<long long>>(n + 1, vector<long long>(2, -(1LL << 60)));
  dp[0][1] = 0;
  for (int r = 1; r <= n; r++) {
    dp[r][0] = max({dp[r][0], dp[r - 1][1], dp[r - 1][0]});
    for (auto i : segs[r]) {
      int l = i.first;
      long long p = i.second;
      dp[r][1] = max({dp[r][1], dp[l][0] + p - a - (r == n ? 0 : 1) * a, dp[l][1] + p - (r == n ? 0 : 1) * a});
    }
  }
  cout << max(dp[n][0], dp[n][1]) << endl;
  return 0;
}
0