結果

問題 No.844 split game
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-06-28 21:54:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 177,016 KB
実行使用メモリ 9,612 KB
最終ジャッジ日時 2023-09-14 21:56:00
合計ジャッジ時間 6,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
8,368 KB
testcase_01 AC 37 ms
8,316 KB
testcase_02 AC 81 ms
9,088 KB
testcase_03 AC 65 ms
8,828 KB
testcase_04 AC 33 ms
8,024 KB
testcase_05 AC 91 ms
9,208 KB
testcase_06 AC 30 ms
8,320 KB
testcase_07 AC 27 ms
8,032 KB
testcase_08 AC 17 ms
7,808 KB
testcase_09 AC 61 ms
8,552 KB
testcase_10 AC 94 ms
9,188 KB
testcase_11 AC 96 ms
9,612 KB
testcase_12 AC 59 ms
8,600 KB
testcase_13 AC 38 ms
8,092 KB
testcase_14 AC 44 ms
8,356 KB
testcase_15 AC 117 ms
9,424 KB
testcase_16 AC 105 ms
9,452 KB
testcase_17 AC 106 ms
9,344 KB
testcase_18 AC 106 ms
9,352 KB
testcase_19 AC 103 ms
9,416 KB
testcase_20 AC 105 ms
9,540 KB
testcase_21 AC 105 ms
9,456 KB
testcase_22 AC 106 ms
9,396 KB
testcase_23 AC 8 ms
7,444 KB
testcase_24 AC 11 ms
7,444 KB
testcase_25 AC 8 ms
7,528 KB
testcase_26 AC 7 ms
7,384 KB
testcase_27 AC 10 ms
7,344 KB
testcase_28 AC 6 ms
7,512 KB
testcase_29 AC 10 ms
7,484 KB
testcase_30 AC 11 ms
7,480 KB
testcase_31 AC 10 ms
7,384 KB
testcase_32 AC 6 ms
7,392 KB
testcase_33 AC 11 ms
7,860 KB
testcase_34 AC 8 ms
7,728 KB
testcase_35 AC 12 ms
7,860 KB
testcase_36 AC 10 ms
7,752 KB
testcase_37 AC 16 ms
7,940 KB
testcase_38 AC 32 ms
8,068 KB
testcase_39 AC 62 ms
8,872 KB
testcase_40 AC 26 ms
8,124 KB
testcase_41 AC 5 ms
7,388 KB
testcase_42 AC 5 ms
7,436 KB
testcase_43 AC 5 ms
7,380 KB
testcase_44 AC 5 ms
7,552 KB
testcase_45 AC 5 ms
7,548 KB
testcase_46 AC 5 ms
7,636 KB
testcase_47 AC 5 ms
7,456 KB
testcase_48 AC 5 ms
7,436 KB
testcase_49 AC 5 ms
7,524 KB
testcase_50 AC 5 ms
7,528 KB
testcase_51 AC 5 ms
7,328 KB
testcase_52 AC 5 ms
7,556 KB
testcase_53 AC 5 ms
7,528 KB
testcase_54 AC 5 ms
7,348 KB
testcase_55 AC 5 ms
7,576 KB
testcase_56 AC 5 ms
7,384 KB
testcase_57 AC 5 ms
7,328 KB
testcase_58 AC 5 ms
7,444 KB
testcase_59 AC 5 ms
7,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def -infl
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/











int N, M, A;
SegTree<ll, 1 << 17> dp;
vector<pair<int, int>> R[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> A;
	rep(i, 0, M) {
		int l, r, p; cin >> l >> r >> p;
		R[r].push_back({ l, p });
	}

	rep(i, 0, N + 1) dp.update(i, -infl);
	dp.update(0, 0);

	rep(r, 1, N + 1) {
		fore(p, R[r]) {
			int l = p.first;
			int q = p.second;

			ll right = A;
			if (r == N) right = 0;

			ll ma = -infl;
			chmax(ma, dp.get(0, l - 1) - A - right + q);
			chmax(ma, dp[l - 1] - right + q);

			dp.update(r, max(dp[r], ma));
		}
	}

	cout << dp.get(0, N + 1) << endl;
}


0