結果

問題 No.844 split game
ユーザー simansiman
提出日時 2023-07-27 18:46:57
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 143,188 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-15 05:41:14
合計ジャッジ時間 5,136 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
6,816 KB
testcase_01 AC 40 ms
11,264 KB
testcase_02 AC 92 ms
8,576 KB
testcase_03 AC 68 ms
11,008 KB
testcase_04 AC 34 ms
6,940 KB
testcase_05 AC 106 ms
11,648 KB
testcase_06 AC 33 ms
6,944 KB
testcase_07 AC 31 ms
9,728 KB
testcase_08 AC 17 ms
6,940 KB
testcase_09 AC 74 ms
6,940 KB
testcase_10 AC 112 ms
10,496 KB
testcase_11 AC 113 ms
12,928 KB
testcase_12 AC 75 ms
6,940 KB
testcase_13 AC 46 ms
6,944 KB
testcase_14 AC 49 ms
9,088 KB
testcase_15 AC 126 ms
13,568 KB
testcase_16 AC 121 ms
13,568 KB
testcase_17 AC 123 ms
13,568 KB
testcase_18 AC 121 ms
13,528 KB
testcase_19 AC 125 ms
13,600 KB
testcase_20 AC 125 ms
13,568 KB
testcase_21 AC 122 ms
13,500 KB
testcase_22 AC 120 ms
13,696 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 9 ms
6,940 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 7 ms
6,944 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 8 ms
6,944 KB
testcase_30 AC 9 ms
6,940 KB
testcase_31 AC 8 ms
6,944 KB
testcase_32 AC 3 ms
6,940 KB
testcase_33 AC 9 ms
6,944 KB
testcase_34 AC 6 ms
6,940 KB
testcase_35 AC 11 ms
6,940 KB
testcase_36 AC 8 ms
6,940 KB
testcase_37 AC 17 ms
6,940 KB
testcase_38 AC 30 ms
6,940 KB
testcase_39 AC 60 ms
6,944 KB
testcase_40 AC 24 ms
7,936 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 1 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 1 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 1 ms
6,944 KB
testcase_53 AC 1 ms
6,940 KB
testcase_54 AC 1 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,944 KB
testcase_57 AC 1 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Range {
  int l;
  int r;
  ll p;

  Range(int l = -1, int r = -1, ll p = 0) {
    this->l = l;
    this->r = r;
    this->p = p;
  }
};

int main() {
  int N, M;
  ll A;
  cin >> N >> M >> A;

  vector<Range> range_list[N + 1];
  for (int i = 0; i < M; ++i) {
    Range range;
    cin >> range.l >> range.r >> range.p;

    range_list[range.l].push_back(range);
  }

  vector<vector<ll>> dp(N + 2, vector<ll>(2, LLONG_MIN));
  dp[1][1] = 0;

  for (int i = 1; i <= N; ++i) {
    dp[i][0] = max(dp[i][0], dp[i - 1][0]);
    dp[i][0] = max(dp[i][0], dp[i - 1][1]);

    for (int j = 0; j < 2; ++j) {
      if (dp[i][j] == LLONG_MIN) continue;

      for (Range &range : range_list[i]) {
        if (j == 0) {
          if (range.r == N) {
            dp[range.r + 1][1] = max(dp[range.r + 1][1], dp[i][j] + range.p - A);
          } else {
            dp[range.r + 1][1] = max(dp[range.r + 1][1], dp[i][j] + range.p - 2 * A);
          }
        } else {
          if (range.r == N) {
            dp[range.r + 1][1] = max(dp[range.r + 1][1], dp[i][j] + range.p);
          } else {
            dp[range.r + 1][1] = max(dp[range.r + 1][1], dp[i][j] + range.p - A);
          }
        }
      }
    }
  }

  ll ans = 0;

  for (int i = 1; i <= N + 1; ++i) {
    for (int j = 0; j < 2; ++j) {
      ans = max(ans, dp[i][j]);
    }
  }

  cout << ans << endl;

  return 0;
}
0