結果

問題 No.844 split game
ユーザー MorikiNMorikiN
提出日時 2020-05-22 10:36:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 7,397 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 185,104 KB
実行使用メモリ 35,020 KB
最終ジャッジ日時 2024-10-04 03:39:52
合計ジャッジ時間 6,039 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
29,832 KB
testcase_01 AC 34 ms
32,840 KB
testcase_02 AC 51 ms
31,296 KB
testcase_03 AC 46 ms
32,884 KB
testcase_04 AC 27 ms
29,612 KB
testcase_05 AC 61 ms
33,496 KB
testcase_06 AC 27 ms
29,648 KB
testcase_07 AC 27 ms
31,744 KB
testcase_08 AC 19 ms
28,640 KB
testcase_09 AC 41 ms
29,468 KB
testcase_10 AC 61 ms
32,772 KB
testcase_11 AC 62 ms
34,436 KB
testcase_12 AC 40 ms
29,320 KB
testcase_13 AC 29 ms
28,528 KB
testcase_14 AC 36 ms
31,400 KB
testcase_15 AC 69 ms
34,924 KB
testcase_16 AC 70 ms
34,948 KB
testcase_17 AC 68 ms
34,968 KB
testcase_18 AC 68 ms
34,816 KB
testcase_19 AC 68 ms
35,020 KB
testcase_20 AC 67 ms
34,932 KB
testcase_21 AC 68 ms
34,952 KB
testcase_22 AC 69 ms
34,956 KB
testcase_23 AC 13 ms
27,340 KB
testcase_24 AC 15 ms
27,652 KB
testcase_25 AC 13 ms
27,360 KB
testcase_26 AC 13 ms
27,484 KB
testcase_27 AC 13 ms
27,296 KB
testcase_28 AC 12 ms
27,600 KB
testcase_29 AC 14 ms
27,656 KB
testcase_30 AC 15 ms
27,728 KB
testcase_31 AC 14 ms
27,552 KB
testcase_32 AC 12 ms
27,480 KB
testcase_33 AC 14 ms
27,432 KB
testcase_34 AC 13 ms
27,268 KB
testcase_35 AC 16 ms
27,504 KB
testcase_36 AC 13 ms
27,244 KB
testcase_37 AC 17 ms
27,532 KB
testcase_38 AC 24 ms
28,504 KB
testcase_39 AC 40 ms
29,700 KB
testcase_40 AC 24 ms
30,328 KB
testcase_41 AC 12 ms
27,148 KB
testcase_42 AC 11 ms
27,024 KB
testcase_43 AC 12 ms
27,192 KB
testcase_44 AC 11 ms
27,000 KB
testcase_45 AC 11 ms
26,996 KB
testcase_46 AC 12 ms
27,064 KB
testcase_47 AC 11 ms
27,120 KB
testcase_48 AC 11 ms
27,036 KB
testcase_49 AC 12 ms
26,976 KB
testcase_50 AC 11 ms
27,040 KB
testcase_51 AC 11 ms
26,996 KB
testcase_52 AC 11 ms
27,036 KB
testcase_53 AC 12 ms
27,080 KB
testcase_54 AC 11 ms
27,124 KB
testcase_55 AC 12 ms
26,996 KB
testcase_56 AC 11 ms
27,152 KB
testcase_57 AC 11 ms
26,992 KB
testcase_58 AC 11 ms
27,172 KB
testcase_59 AC 11 ms
27,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>
#include <complex>
#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define drep(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define fore(c,v) for(auto (c): (v))
#define lp for(int __=0;__<n;i++)
#define mem(a,b) memset(a,b,sizeof(a));
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;

const int Mod = (1e9) + 7;
const int INF = 1e9 + 19;
const ll INFL = 1e18 + 19;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
const int dy2[] = {1, 0, -1, 1, 0, -1, 1, 0, -1};
const double EPS = 1e-10;
//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

bool pairsort(pll pl, pll pr){
  if(pl.first == pr.first)return pl.second > pr.second;
  return pl.first < pr.first;
}

int cntbit(ll a,int n,int j){int res = 0;For(i,j,n){if(a>>i & 1){res++;}}return res;}
vector<int> make_bit(int a){vector<int> res; for(int i=31;i>=0;i--)if(a&(1<<i))res.pb(i);return res;}
bool stdbit(int a, int b){return a&(1 << b); }
int GCD(int a, int b){if(b > a)return GCD(b,a);if(a%b == 0)return b;else return GCD(b, a%b);}
int LCM(int a, int b){return a*b/GCD(a,b);}
int roundup(int a, int b){if(a % b == 0)return a/b;else return (a+b)/b;}
int rounddown(int a, int b){if(a%b == 0)return a/b;else {return (a-b)/b;}}
ll pow(ll a, ll n){ll res = 1;while(n > 0){if(n&1)res *= a; a *= a; n = n >> 1;}return res;}
ll GetDiviserCount(ll N)//約数の個数
{
  ll res = 1;
  For(i,2,sqrt(N)+1)
  {
    ll cnt = 0;
    while(N%i == 0)
    {
      cnt++;
      N /= i;
    }
    res *= (cnt + 1);
    if(N == 1)break;
  }
  if(N != 1)res *= 2;
  return res;
}
vll GetDivisor(ll N)//約数列挙
{
  vll res;
  for(ll i = 1;i*i <= N;i++)
  {
    if(N%i == 0)
    {
      res.pb(i);
      if(i*i != N)res.pb(N/i);
    }
  }
  sort(All(res));
  return res;
}


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%Mod+Mod)%Mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += Mod-a.x) >= Mod) x -= Mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= Mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(Mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const mint& a);
};
ostream& operator<<(ostream& os, const mint& a)
{
  os << a.x;
  return os;
}
using vm = vector<mint>;
using vvm = vector<vm>;
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < Mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
 
template<class Z>
struct MyMatrix
{
  using mat = MyMatrix<Z>;
  vector<vector<Z>> m_dat;
  int m_h;
  int m_w;
  MyMatrix(int h, int w) : m_h(h), m_w(w) ,m_dat(h,vector<Z>(w)) {}
  vector<Z> &operator[] (int idx)
  {
    return m_dat[idx];
  }
  mat Multiple(mat &a)
  {
    mat C(m_h, a.m_w);
    for(int i=0;i<m_h;i++)
    {
      for(int j=0;j<a.m_w;j++)
      {
        for(int k=0;k<m_w;k++)
        {
         C[i][j] += m_dat[i][k] * a[k][j];
        }
      }
    }
    return C;
  }
  mat Pow(ll x)
  {
    mat B(m_h,m_w);
    for(int i=0;i<m_h;i++)
    {
      B[i][i] = 1;
    }
    mat A = *this;
    while(x > 0)
    {
      if(x&1)B = B.Multiple(A);
      A = A.Multiple(A);
      x = x >> 1;
    }
    return B;
  }
  //friend ostream& operator<<(ostream &os, const mat &A);
};
/*
template<class Z>
ostream& operator<<(ostream &os, Matrix<Z>& A)
{
  for(int i=0;i<A.m_h;i++)
  {
    for(int j=0;j<A.m_w;j++)
    {
      os << A[i][j] << " ";
    }
    os << endl;
  }
  return os;
}
*/
template<class T>
using mat = MyMatrix<T>;
//_____________________ following sorce code_________________________//
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;

int n,m,k;
ll N;
int h,w;
string S;
int a,b,c;
vi v;
int ans;
double x,y,z;
struct Data
{
  int left;
  ll x;
  Data(int left,ll x) : left(left), x(x) {}
};
vector<Data> G[1010101];
signed main (int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  IN(n,m,a);
  ll ans = 0;
  rep(i,m)
  {
    ll x;
    int l,r;
    IN(l,r,x);
    l--;
    G[r].push_back(Data(l,x));
  }
  vvll dp(n+1,vll(2));
  dp[0][1] = 0;
  For(i,1,n+1)
  {
    dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
    dp[i][1] = max(0ll, max(dp[i-1][0],dp[i-1][1]))- a;
    fore(e,G[i])
    {
      int left = e.left;
      ll x = e.x;
      if(i != n)chmax(dp[i][1],dp[left][1] + x - a);
      else chmax(dp[i][1], dp[left][1] + x);
    }
    chmax(ans,dp[i][0]);
    chmax(ans,dp[i][1]);
  }
  pri(ans);
  //for(auto c : ans){cout << c << endl;}
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}
0