結果

問題 No.844 split game
ユーザー DAyamaCTFDAyamaCTF
提出日時 2019-06-28 21:53:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 147,924 KB
実行使用メモリ 10,096 KB
最終ジャッジ日時 2023-09-14 21:55:26
合計ジャッジ時間 5,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
7,344 KB
testcase_01 AC 19 ms
8,096 KB
testcase_02 AC 46 ms
8,780 KB
testcase_03 AC 33 ms
8,588 KB
testcase_04 AC 17 ms
7,104 KB
testcase_05 AC 48 ms
9,228 KB
testcase_06 AC 16 ms
6,960 KB
testcase_07 AC 14 ms
7,508 KB
testcase_08 AC 10 ms
6,536 KB
testcase_09 AC 32 ms
8,072 KB
testcase_10 AC 51 ms
9,252 KB
testcase_11 AC 49 ms
9,708 KB
testcase_12 AC 32 ms
7,784 KB
testcase_13 AC 21 ms
7,080 KB
testcase_14 AC 23 ms
7,976 KB
testcase_15 AC 54 ms
9,948 KB
testcase_16 AC 54 ms
9,908 KB
testcase_17 AC 55 ms
9,948 KB
testcase_18 AC 54 ms
9,924 KB
testcase_19 AC 55 ms
9,896 KB
testcase_20 AC 54 ms
10,096 KB
testcase_21 AC 52 ms
9,948 KB
testcase_22 AC 53 ms
9,956 KB
testcase_23 AC 5 ms
5,980 KB
testcase_24 AC 6 ms
6,200 KB
testcase_25 AC 6 ms
5,940 KB
testcase_26 AC 4 ms
6,044 KB
testcase_27 AC 6 ms
5,932 KB
testcase_28 AC 4 ms
5,932 KB
testcase_29 AC 6 ms
6,088 KB
testcase_30 AC 6 ms
5,996 KB
testcase_31 AC 6 ms
5,964 KB
testcase_32 AC 4 ms
5,900 KB
testcase_33 AC 7 ms
5,960 KB
testcase_34 AC 6 ms
6,108 KB
testcase_35 AC 8 ms
5,948 KB
testcase_36 AC 6 ms
5,936 KB
testcase_37 AC 9 ms
5,948 KB
testcase_38 AC 16 ms
6,928 KB
testcase_39 AC 33 ms
8,412 KB
testcase_40 AC 13 ms
7,316 KB
testcase_41 AC 4 ms
5,836 KB
testcase_42 AC 4 ms
5,728 KB
testcase_43 AC 3 ms
5,716 KB
testcase_44 AC 3 ms
5,880 KB
testcase_45 AC 3 ms
5,764 KB
testcase_46 AC 3 ms
5,700 KB
testcase_47 AC 4 ms
5,656 KB
testcase_48 AC 3 ms
5,832 KB
testcase_49 AC 3 ms
5,628 KB
testcase_50 AC 3 ms
5,776 KB
testcase_51 AC 3 ms
5,716 KB
testcase_52 AC 4 ms
5,924 KB
testcase_53 AC 4 ms
5,756 KB
testcase_54 AC 3 ms
5,812 KB
testcase_55 AC 4 ms
5,684 KB
testcase_56 AC 4 ms
5,656 KB
testcase_57 AC 4 ms
5,780 KB
testcase_58 AC 4 ms
5,724 KB
testcase_59 AC 4 ms
5,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,M,A;
vector<P> rs[100010];
ll dp[100010][2];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N>>M>>A;
  rep(i,M){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    rs[b].push_back(P(a,c));
  }

  rep(i,N+1)dp[i][0]=dp[i][1]=-INF;

  dp[0][1]=0;
  repl(i,1,N+1){
    for(P r : rs[i]){
      if(i<N){
        maxch(dp[i][1],dp[r.fi][0]+r.se-2*A);
        maxch(dp[i][1],dp[r.fi][1]+r.se-A);
      }else{
        maxch(dp[i][1],dp[r.fi][0]+r.se-A);
        maxch(dp[i][1],dp[r.fi][1]+r.se);
      }
    }
    maxch(dp[i][0],dp[i-1][0]);
    maxch(dp[i][0],dp[i-1][1]);
  }
  cout<<max(dp[N][0],dp[N][1])<<endl;

  return 0;
}
0