結果

問題 No.1014 competitive fighting
ユーザー MisterMister
提出日時 2020-05-02 02:43:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,080 bytes
コンパイル時間 1,345 ms
コンパイル使用メモリ 97,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 21:34:20
合計ジャッジ時間 9,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using lint = long long;
constexpr lint INF = 1LL << 60;

struct Item {
    lint a, b, c;
    int id;
};

void solve() {
    int n;
    std::cin >> n;

    std::vector<Item> ts(n);
    for (int i = 0; i < n; ++i) {
        auto& t = ts[i];
        std::cin >> t.a >> t.b >> t.c;
        t.id = i;
    }

    std::sort(ts.begin(), ts.end(),
              [](auto lhs, auto rhs) {
                  return lhs.a < rhs.a;
              });

    std::vector<lint> ans(n, -1), acc(n, -1);
    std::function<lint(int)> dfs =
        [&](int v) -> lint {
        if (ans[v] != -1) {
            if (v > 0 && acc[v - 1] != -1) {
                acc[v] = std::max(ans[v], acc[v - 1]);
            }
            return ans[v];
        }

        int ok = -1, ng = n;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (ts[mid].a <= ts[v].b - ts[v].c) {
                ok = mid;
            } else {
                ng = mid;
            }
        }

        if (ok == -1) {
            ans[v] = ts[v].b;
            return ans[v];
        }

        lint res = 0;
        ans[v] = INF;

        for (int u = ok; u >= 0; --u) {
            if (u == v) continue;
            if (acc[u] != -1) {
                res = std::max(res, acc[u] + ts[v].b);
                break;
            } else {
                res = std::max(res, dfs(u) + ts[v].b);
            }
        }

        if (res >= INF) res = INF;

        ans[v] = res;
        if (v == 0) {
            acc[v] = ans[v];
        } else if (acc[v - 1] != -1) {
            acc[v] = std::max(ans[v], acc[v - 1]);
        }

        return ans[v];
    };

    std::vector<lint> as(n);
    for (int v = 0; v < n; ++v) as[ts[v].id] = dfs(v);

    for (auto a : as) {
        if (a == INF) {
            std::cout << "BAN" << std::endl;
        } else {
            std::cout << a << std::endl;
        }
    }
}

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

    solve();

    return 0;
}
0