結果

問題 No.844 split game
ユーザー lumc_lumc_
提出日時 2019-06-28 21:45:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 4,676 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 113,388 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-07-02 04:32:52
合計ジャッジ時間 3,853 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,192 KB
testcase_01 AC 18 ms
9,088 KB
testcase_02 AC 39 ms
9,856 KB
testcase_03 AC 31 ms
9,984 KB
testcase_04 AC 17 ms
7,936 KB
testcase_05 AC 46 ms
10,752 KB
testcase_06 AC 17 ms
7,936 KB
testcase_07 AC 14 ms
8,192 KB
testcase_08 AC 10 ms
7,040 KB
testcase_09 AC 31 ms
8,704 KB
testcase_10 AC 46 ms
10,752 KB
testcase_11 AC 44 ms
11,264 KB
testcase_12 AC 30 ms
8,576 KB
testcase_13 AC 20 ms
7,680 KB
testcase_14 AC 21 ms
8,832 KB
testcase_15 AC 49 ms
11,776 KB
testcase_16 AC 50 ms
11,648 KB
testcase_17 AC 48 ms
11,776 KB
testcase_18 AC 49 ms
11,776 KB
testcase_19 AC 48 ms
11,904 KB
testcase_20 AC 47 ms
11,776 KB
testcase_21 AC 48 ms
11,776 KB
testcase_22 AC 49 ms
11,648 KB
testcase_23 AC 5 ms
6,144 KB
testcase_24 AC 7 ms
6,400 KB
testcase_25 AC 5 ms
6,272 KB
testcase_26 AC 4 ms
6,144 KB
testcase_27 AC 6 ms
6,272 KB
testcase_28 AC 4 ms
6,144 KB
testcase_29 AC 6 ms
6,400 KB
testcase_30 AC 7 ms
6,528 KB
testcase_31 AC 6 ms
6,272 KB
testcase_32 AC 4 ms
6,272 KB
testcase_33 AC 7 ms
6,400 KB
testcase_34 AC 5 ms
6,272 KB
testcase_35 AC 8 ms
6,400 KB
testcase_36 AC 6 ms
6,272 KB
testcase_37 AC 9 ms
6,656 KB
testcase_38 AC 15 ms
7,552 KB
testcase_39 AC 28 ms
9,088 KB
testcase_40 AC 12 ms
7,680 KB
testcase_41 AC 4 ms
6,016 KB
testcase_42 AC 4 ms
5,888 KB
testcase_43 AC 4 ms
6,144 KB
testcase_44 AC 4 ms
6,016 KB
testcase_45 AC 4 ms
6,016 KB
testcase_46 AC 4 ms
6,016 KB
testcase_47 AC 4 ms
6,016 KB
testcase_48 AC 4 ms
5,888 KB
testcase_49 AC 4 ms
6,016 KB
testcase_50 AC 4 ms
6,016 KB
testcase_51 AC 4 ms
6,016 KB
testcase_52 AC 4 ms
6,016 KB
testcase_53 AC 5 ms
6,144 KB
testcase_54 AC 4 ms
5,888 KB
testcase_55 AC 4 ms
6,016 KB
testcase_56 AC 4 ms
6,016 KB
testcase_57 AC 4 ms
6,016 KB
testcase_58 AC 4 ms
6,016 KB
testcase_59 AC 4 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
#define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) ((void) 42)
#define dump2D(...) ((void) 42)
#define dump1D(...) ((void) 42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}


ll dp[112345];
ll dp2[112345];

ll l[112345], r[112345], p[112345];

vector<int> q[112345];

template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  ll a;
  cin >> n >> m >> a;

  for(int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> p[i];
    q[r[i] + 1].push_back(i);
  }

  for(int i = 2; i <= n + 1; i++) {
    dp[i] = -1e18;
    for(int j : q[i]) {
      smax(dp[i], dp[l[j]] + p[j] - a + a * (i == n + 1));
      smax(dp[i], dp2[l[j]-1] + p[j] - 2 * a + a * (i == n + 1));
    }
    dp2[i] = max(dp2[i-1], dp[i]);
  }

  cout << dp2[n + 1] << endl;
  return 0;
}
0