結果
問題 | No.1014 competitive fighting |
ユーザー | kibuna |
提出日時 | 2020-03-23 23:02:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 664 ms / 2,000 ms |
コード長 | 3,238 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 189,272 KB |
実行使用メモリ | 106,992 KB |
最終ジャッジ日時 | 2024-07-07 13:00:21 |
合計ジャッジ時間 | 20,636 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 664 ms
95,188 KB |
testcase_06 | AC | 659 ms
95,064 KB |
testcase_07 | AC | 654 ms
95,188 KB |
testcase_08 | AC | 652 ms
95,060 KB |
testcase_09 | AC | 639 ms
95,148 KB |
testcase_10 | AC | 174 ms
27,652 KB |
testcase_11 | AC | 218 ms
36,836 KB |
testcase_12 | AC | 635 ms
95,060 KB |
testcase_13 | AC | 269 ms
46,652 KB |
testcase_14 | AC | 218 ms
43,004 KB |
testcase_15 | AC | 277 ms
51,032 KB |
testcase_16 | AC | 10 ms
5,376 KB |
testcase_17 | AC | 86 ms
20,224 KB |
testcase_18 | AC | 515 ms
78,384 KB |
testcase_19 | AC | 622 ms
92,716 KB |
testcase_20 | AC | 175 ms
34,888 KB |
testcase_21 | AC | 459 ms
71,104 KB |
testcase_22 | AC | 375 ms
59,264 KB |
testcase_23 | AC | 113 ms
25,344 KB |
testcase_24 | AC | 120 ms
26,136 KB |
testcase_25 | AC | 27 ms
8,704 KB |
testcase_26 | AC | 455 ms
69,984 KB |
testcase_27 | AC | 85 ms
20,096 KB |
testcase_28 | AC | 96 ms
22,144 KB |
testcase_29 | AC | 6 ms
5,376 KB |
testcase_30 | AC | 638 ms
91,880 KB |
testcase_31 | AC | 479 ms
73,500 KB |
testcase_32 | AC | 5 ms
5,376 KB |
testcase_33 | AC | 28 ms
9,728 KB |
testcase_34 | AC | 461 ms
83,116 KB |
testcase_35 | AC | 639 ms
106,992 KB |
testcase_36 | AC | 419 ms
75,512 KB |
testcase_37 | AC | 11 ms
5,888 KB |
testcase_38 | AC | 368 ms
69,244 KB |
testcase_39 | AC | 169 ms
36,600 KB |
testcase_40 | AC | 358 ms
68,124 KB |
testcase_41 | AC | 238 ms
48,872 KB |
testcase_42 | AC | 638 ms
105,292 KB |
testcase_43 | AC | 25 ms
8,832 KB |
testcase_44 | AC | 542 ms
95,744 KB |
testcase_45 | AC | 287 ms
57,340 KB |
testcase_46 | AC | 41 ms
12,800 KB |
testcase_47 | AC | 144 ms
34,304 KB |
testcase_48 | AC | 404 ms
77,520 KB |
testcase_49 | AC | 13 ms
6,400 KB |
testcase_50 | AC | 568 ms
100,724 KB |
testcase_51 | AC | 290 ms
59,988 KB |
testcase_52 | AC | 15 ms
6,784 KB |
testcase_53 | AC | 658 ms
95,192 KB |
ソースコード
#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; } 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; }