結果

問題 No.844 split game
ユーザー TiramisterTiramister
提出日時 2019-06-28 21:57:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,074 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 118,544 KB
実行使用メモリ 10,244 KB
最終ジャッジ日時 2023-09-14 21:56:46
合計ジャッジ時間 5,797 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
5,968 KB
testcase_01 AC 34 ms
5,180 KB
testcase_02 AC 104 ms
9,692 KB
testcase_03 AC 70 ms
7,664 KB
testcase_04 AC 39 ms
5,576 KB
testcase_05 AC 113 ms
9,428 KB
testcase_06 AC 36 ms
4,964 KB
testcase_07 AC 25 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 90 ms
8,336 KB
testcase_10 AC 123 ms
10,064 KB
testcase_11 AC 114 ms
9,532 KB
testcase_12 AC 92 ms
8,424 KB
testcase_13 AC 54 ms
6,224 KB
testcase_14 AC 48 ms
5,812 KB
testcase_15 AC 124 ms
10,184 KB
testcase_16 AC 125 ms
10,232 KB
testcase_17 AC 126 ms
10,244 KB
testcase_18 AC 124 ms
10,240 KB
testcase_19 AC 125 ms
10,188 KB
testcase_20 AC 125 ms
10,188 KB
testcase_21 AC 124 ms
10,200 KB
testcase_22 AC 124 ms
10,196 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 12 ms
4,376 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 15 ms
4,380 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 21 ms
4,612 KB
testcase_38 AC 37 ms
5,996 KB
testcase_39 AC 75 ms
9,164 KB
testcase_40 AC 20 ms
4,676 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 WA -
testcase_48 AC 2 ms
4,380 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 1 ms
4,380 KB
testcase_52 WA -
testcase_53 AC 1 ms
4,376 KB
testcase_54 WA -
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 3 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

struct Seg {
    int l, r;
    lint p;
    Seg(int l = 0, int r = 0, lint p = 0) : l(l), r(r), p(p) {}
    bool operator<(const Seg& a) const {
        return l == a.l ? r < a.r : l < a.l;
    }
};

int main() {
    int N, M, A;
    cin >> N >> M >> A;

    vector<Seg> segs(M);
    for (auto& s : segs) {
        cin >> s.l >> s.r >> s.p;
    }
    sort(segs.begin(), segs.end());

    auto dp = Vec<lint>(M + 1, 2, -INF);
    dp[0][1] = 0;
    // dp[i][b] = [0, i)まで見て、
    //            segs[i].lの左に線が引かれて[いる/いない]ときの最適解

    for (int i = 0; i < M; ++i) {
        // iを使わない場合
        if (segs[i + 1].l == segs[i].l) {
            // 既に左に線が引かれている可能性あり
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0]);
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1]);
        } else {
            dp[i + 1][0] = max({dp[i + 1][0], dp[i][0], dp[i][1]});
        }

        // iを使う場合
        // segs[i]とsegs[j]が交わらない最小のjを求める
        int j = lower_bound(segs.begin(), segs.end(), Seg(segs[i].r + 1, -1)) -
                segs.begin();

        int cost = A * 2;
        if (segs[i].r == N) cost -= A;

        bool b = (j < M && segs[j].l == segs[i].r + 1);
        dp[j][b] = max({dp[j][b],
                        dp[i][0] + segs[i].p - cost,
                        dp[i][1] + segs[i].p - (cost - A)});
    }

    cout << max(dp[M][0], dp[M][1]) << endl;
    return 0;
}
0