結果

問題 No.844 split game
ユーザー simansiman
提出日時 2023-07-27 18:43:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,606 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 141,440 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-15 05:38:45
合計ジャッジ時間 5,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
6,016 KB
testcase_01 AC 31 ms
7,936 KB
testcase_02 AC 83 ms
7,424 KB
testcase_03 AC 61 ms
8,320 KB
testcase_04 AC 31 ms
5,504 KB
testcase_05 WA -
testcase_06 AC 31 ms
5,632 KB
testcase_07 AC 26 ms
7,040 KB
testcase_08 WA -
testcase_09 AC 73 ms
6,016 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 70 ms
6,016 KB
testcase_13 AC 45 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 107 ms
9,856 KB
testcase_16 AC 109 ms
9,928 KB
testcase_17 AC 109 ms
9,984 KB
testcase_18 AC 107 ms
9,856 KB
testcase_19 WA -
testcase_20 AC 108 ms
9,856 KB
testcase_21 AC 102 ms
9,856 KB
testcase_22 AC 107 ms
9,984 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 7 ms
5,376 KB
testcase_31 WA -
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 9 ms
5,376 KB
testcase_34 WA -
testcase_35 AC 11 ms
5,376 KB
testcase_36 AC 7 ms
5,376 KB
testcase_37 AC 16 ms
5,376 KB
testcase_38 AC 28 ms
5,376 KB
testcase_39 AC 58 ms
6,272 KB
testcase_40 AC 18 ms
6,272 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 WA -
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 1 ms
5,376 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);
  }

  ll dp[N + 2][2];
  memset(dp, -1, sizeof(dp));
  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] == -1) 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