結果

問題 No.844 split game
ユーザー LayCurseLayCurse
提出日時 2019-07-06 15:16:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,518 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 207,732 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-10-26 00:04:34
合計ジャッジ時間 6,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,008 KB
testcase_01 AC 8 ms
8,404 KB
testcase_02 AC 17 ms
8,048 KB
testcase_03 AC 13 ms
8,352 KB
testcase_04 AC 8 ms
7,996 KB
testcase_05 AC 18 ms
8,352 KB
testcase_06 AC 7 ms
8,020 KB
testcase_07 AC 6 ms
8,348 KB
testcase_08 AC 5 ms
7,936 KB
testcase_09 AC 15 ms
7,852 KB
testcase_10 AC 19 ms
8,236 KB
testcase_11 AC 18 ms
8,404 KB
testcase_12 AC 14 ms
7,828 KB
testcase_13 AC 9 ms
7,828 KB
testcase_14 AC 9 ms
8,232 KB
testcase_15 AC 19 ms
8,404 KB
testcase_16 AC 19 ms
8,404 KB
testcase_17 AC 19 ms
8,404 KB
testcase_18 AC 19 ms
8,404 KB
testcase_19 AC 20 ms
8,404 KB
testcase_20 AC 20 ms
8,404 KB
testcase_21 AC 19 ms
8,404 KB
testcase_22 AC 19 ms
8,404 KB
testcase_23 AC 3 ms
7,772 KB
testcase_24 AC 4 ms
7,812 KB
testcase_25 AC 3 ms
7,748 KB
testcase_26 AC 3 ms
7,776 KB
testcase_27 AC 3 ms
7,752 KB
testcase_28 AC 3 ms
7,800 KB
testcase_29 AC 4 ms
7,816 KB
testcase_30 AC 3 ms
7,812 KB
testcase_31 AC 3 ms
7,768 KB
testcase_32 AC 3 ms
7,788 KB
testcase_33 AC 5 ms
7,740 KB
testcase_34 AC 3 ms
7,740 KB
testcase_35 AC 5 ms
7,740 KB
testcase_36 AC 4 ms
7,740 KB
testcase_37 AC 6 ms
7,740 KB
testcase_38 AC 5 ms
7,796 KB
testcase_39 AC 8 ms
7,872 KB
testcase_40 AC 4 ms
8,148 KB
testcase_41 AC 2 ms
7,740 KB
testcase_42 AC 2 ms
7,740 KB
testcase_43 AC 2 ms
7,740 KB
testcase_44 AC 2 ms
7,740 KB
testcase_45 AC 3 ms
7,740 KB
testcase_46 AC 2 ms
7,740 KB
testcase_47 AC 3 ms
7,740 KB
testcase_48 AC 2 ms
7,740 KB
testcase_49 AC 2 ms
7,740 KB
testcase_50 AC 3 ms
7,740 KB
testcase_51 AC 3 ms
7,740 KB
testcase_52 AC 3 ms
7,740 KB
testcase_53 AC 2 ms
7,740 KB
testcase_54 AC 2 ms
7,740 KB
testcase_55 AC 2 ms
7,740 KB
testcase_56 AC 2 ms
7,740 KB
testcase_57 AC 2 ms
7,740 KB
testcase_58 AC 3 ms
7,740 KB
testcase_59 AC 2 ms
7,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T1, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  int i;
  pair<T1, pair<T2, T3> > *arr=(pair<T1, pair<T2, T3> > *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second.first = b[i];
    arr[i].second.second = c[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second.first;
    c[i] = arr[i].second.second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
char memarr[96000000];
int N;
int M;
int A;
int L[100000];
int R[100000];
int P[100000];
long long dp[100001];
long long mx[100001];
int main(){
  int i, j, k;
  long long res;
  wmem = memarr;
  rd(N);
  rd(M);
  rd(A);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<M;Lj4PdHRW++){
      rd(L[Lj4PdHRW]);L[Lj4PdHRW] += (-1);
      rd(R[Lj4PdHRW]);
      rd(P[Lj4PdHRW]);
    }
  }
  sortA_L(M, L, R, P);
  for(i=1;i<N+1;i++){
    dp[i]=-4611686016279904256LL;
  }
  k = 0;
  for(i=0;i<N+1;i++){
    mx[i] =max_L(mx[i-1], dp[i]);
    chmax(dp[i], mx[i-1] - A);
    while(k < M && L[k]==i){
      chmax(dp[R[k]], dp[i] + P[k] - A);
      k++;
    }
  }
  res =max_L(mx[N], dp[N]+A);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int N, M, A;
// int L[1d5], R[1d5], P[1d5];
// ll dp[100001], mx[100001];
// {
//   int i, j, k;
//   ll res;
// 
//   rd(N,M,A,(L--,R,P)(M));
//   sortA(M, L, R, P);
// 
//   rep(i,1,N+1) dp[i]=-ll_inf;
// 
//   k = 0;
//   rep(i,N+1){
//     mx[i] = max(mx[i-1], dp[i]);
//     dp[i] >?= mx[i-1] - A;
//     while(k < M && L[k]==i){
//       dp[R[k]] >?= dp[i] + P[k] - A;
//       k++;
//     }
//   }
// 
//   res = max(mx[N], dp[N]+A);
//   wt(res);
// }
0