結果

問題 No.844 split game
ユーザー seriru13seriru13
提出日時 2019-09-07 11:22:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 116,620 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-09-08 13:32:20
合計ジャッジ時間 4,132 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
5,188 KB
testcase_01 AC 15 ms
6,664 KB
testcase_02 AC 37 ms
6,628 KB
testcase_03 AC 27 ms
7,340 KB
testcase_04 AC 14 ms
5,080 KB
testcase_05 AC 41 ms
7,788 KB
testcase_06 AC 14 ms
4,908 KB
testcase_07 AC 12 ms
6,216 KB
testcase_08 AC 8 ms
4,412 KB
testcase_09 AC 29 ms
5,560 KB
testcase_10 AC 43 ms
7,432 KB
testcase_11 AC 43 ms
8,232 KB
testcase_12 AC 28 ms
5,496 KB
testcase_13 AC 19 ms
4,648 KB
testcase_14 AC 20 ms
6,120 KB
testcase_15 AC 47 ms
8,792 KB
testcase_16 AC 46 ms
8,792 KB
testcase_17 AC 46 ms
8,772 KB
testcase_18 AC 47 ms
8,928 KB
testcase_19 AC 46 ms
8,932 KB
testcase_20 AC 43 ms
8,800 KB
testcase_21 AC 44 ms
8,864 KB
testcase_22 AC 48 ms
8,840 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 7 ms
4,376 KB
testcase_38 AC 14 ms
4,732 KB
testcase_39 AC 27 ms
5,916 KB
testcase_40 AC 10 ms
5,516 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 長さNの線があって、そのうちいくつかの区間に制約があるという状況で何かを最適化する、
// という問題ではDPが有効な場合がある。

using P = pair<ll,ll>;

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

    ll n, m, a;
    cin >> n >> m >> a;

    vector<vector<P>> v(n+1);
    ll p;
    rep(i, m) {
        int l,r;
        cin >> l >> r >> p;
        v[r].push_back(P(l, p));
    }

    ll ma = 0;
    vector<ll> dp(n+100);
    for (int i = 1; i <= n; ++i) {
        dp[i] = ma - a;
        for (auto x : v[i]) {
            dp[i] = max(dp[i], dp[x.first - 1] + x.second - (i == n ? 0 : a));
        }
        ma = max(ma, dp[i]);
    }

    cout << ma << endl;
}
0