結果

問題 No.1014 competitive fighting
ユーザー kibunakibuna
提出日時 2020-03-23 22:57:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,240 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 188,252 KB
実行使用メモリ 106,196 KB
最終ジャッジ日時 2023-08-28 13:15:42
合計ジャッジ時間 25,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 184 ms
27,476 KB
testcase_11 AC 218 ms
36,704 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 30 ms
9,724 KB
testcase_34 AC 525 ms
82,648 KB
testcase_35 AC 712 ms
106,196 KB
testcase_36 AC 463 ms
75,196 KB
testcase_37 AC 12 ms
5,660 KB
testcase_38 AC 419 ms
69,076 KB
testcase_39 AC 188 ms
36,164 KB
testcase_40 AC 404 ms
67,920 KB
testcase_41 AC 257 ms
48,508 KB
testcase_42 AC 718 ms
104,984 KB
testcase_43 AC 25 ms
8,812 KB
testcase_44 AC 630 ms
95,412 KB
testcase_45 AC 337 ms
56,948 KB
testcase_46 AC 46 ms
12,524 KB
testcase_47 AC 170 ms
33,848 KB
testcase_48 AC 490 ms
77,100 KB
testcase_49 AC 15 ms
6,380 KB
testcase_50 AC 652 ms
100,108 KB
testcase_51 AC 341 ms
59,676 KB
testcase_52 AC 16 ms
6,492 KB
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1e15;
const lint mod = 1000000007;

struct StronglyConnectedComponents {
    vector<vector<int>> const &edges_in;
    vector<vector<int>> edges, rev, dag;
    vector<int> comp, order, used;
    vector<vector<int>> cs; // list of nodes in each component

    StronglyConnectedComponents(vector<vector<int>> const &g)
        : edges_in(g), edges(g.size()), rev(g.size()), comp(g.size(), -1), used(g.size()), cs(g.size()) {
        for (int i = 0; i < (int)edges_in.size(); ++i) {
            for (auto &v : edges_in[i]) {
                edges[i].push_back(v);
                rev[v].push_back(i);
            }
        }
        build();
    }
    int operator[](int k) { return comp[k]; }
    void dfs(int c) {
        if (used[c])
            return;
        used[c] = true;
        for (auto &v : edges[c])
            dfs(v);
        order.push_back(c);
    }
    void rdfs(int c, int cnt) {
        if (comp[c] != -1)
            return;
        comp[c] = cnt;
        cs[cnt].emplace_back(c);
        for (auto &v : rev[c])
            rdfs(v, cnt);
    }
    void build() {
        for (int i = 0; i < (int)edges.size(); ++i)
            dfs(i);
        reverse(order.begin(), order.end());
        int ptr = 0;
        for (auto &i : order) {
            if (comp[i] == -1)
                rdfs(i, ptr++);
        }
        dag.resize(ptr);
        for (int i = 0; i < (int)edges_in.size(); ++i) {
            int x = comp[i];
            for (auto &v : edges_in[i]) {
                int y = comp[v];
                if (x == y)
                    continue;
                dag[x].push_back(y);
            }
        }
    }
};

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    map<lint, lint> idx;
    vector<lint> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        idx[a[i]]        = 0;
        idx[b[i] - c[i]] = 0;
    }
    int id = 0;
    for (auto &p : idx) {
        p.second = id++;
    }
    int k = idx.size();
    vector<vector<int>> edges(n + k);
    for (int i = 0; i < k - 1; ++i) {
        edges[i].push_back(i + 1);
    }
    for (int i = k; i < k + n; ++i) {
        edges[i].push_back(idx[a[i - k]]);
        edges[idx[b[i - k] - c[i - k]]].push_back(i);
    }
    StronglyConnectedComponents scc(edges);
    vector<int> cnt(n + k, 0);
    for (int i = k; i < n + k; ++i) {
        cnt[scc[i]]++;
    }
    lint m = scc.dag.size();
    vector<lint> dp(m, 0);

    for (int i = 0; i < m; ++i) {
        if (cnt[i] > 1) {
            dp[i] = inf;
            continue;
        }
        for (auto &v : scc.cs[i]) {
            if (v >= k)
                dp[i] += b[v - k];
        }
        for (auto &v : scc.dag[i]) {
            chmax(dp[v], dp[i]);
        }
    }
    for (int i = k; i < k + n; ++i) {
        if (dp[scc[i]] >= inf)
            cout << "BAN" << endl;
        else
            cout << dp[scc[i]] << endl;
    }
    return 0;
}
0