結果
問題 | No.1014 competitive fighting |
ユーザー | kibuna |
提出日時 | 2020-03-23 22:58:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,260 bytes |
コンパイル時間 | 2,022 ms |
コンパイル使用メモリ | 189,592 KB |
実行使用メモリ | 106,888 KB |
最終ジャッジ日時 | 2024-06-09 08:39:11 |
合計ジャッジ時間 | 21,559 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 181 ms
27,656 KB |
testcase_11 | AC | 209 ms
36,712 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,728 KB |
testcase_34 | AC | 486 ms
83,016 KB |
testcase_35 | AC | 698 ms
106,888 KB |
testcase_36 | AC | 457 ms
75,520 KB |
testcase_37 | AC | 12 ms
6,940 KB |
testcase_38 | AC | 390 ms
69,232 KB |
testcase_39 | AC | 183 ms
36,600 KB |
testcase_40 | AC | 374 ms
68,128 KB |
testcase_41 | AC | 240 ms
48,876 KB |
testcase_42 | AC | 654 ms
105,384 KB |
testcase_43 | AC | 25 ms
8,832 KB |
testcase_44 | AC | 585 ms
95,640 KB |
testcase_45 | AC | 289 ms
57,260 KB |
testcase_46 | AC | 40 ms
12,672 KB |
testcase_47 | AC | 150 ms
34,300 KB |
testcase_48 | AC | 464 ms
77,592 KB |
testcase_49 | AC | 14 ms
6,940 KB |
testcase_50 | AC | 619 ms
100,660 KB |
testcase_51 | AC | 325 ms
60,108 KB |
testcase_52 | AC | 15 ms
6,940 KB |
testcase_53 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; 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] < inf) 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; }