結果
問題 | No.1014 competitive fighting |
ユーザー | jupiro |
提出日時 | 2020-03-23 19:48:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 191 ms / 2,000 ms |
コード長 | 3,413 bytes |
コンパイル時間 | 1,868 ms |
コンパイル使用メモリ | 137,608 KB |
実行使用メモリ | 86,232 KB |
最終ジャッジ日時 | 2024-07-07 12:59:55 |
合計ジャッジ時間 | 7,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 147 ms
40,588 KB |
testcase_06 | AC | 149 ms
40,648 KB |
testcase_07 | AC | 148 ms
40,580 KB |
testcase_08 | AC | 151 ms
40,792 KB |
testcase_09 | AC | 149 ms
40,728 KB |
testcase_10 | AC | 191 ms
86,232 KB |
testcase_11 | AC | 80 ms
22,756 KB |
testcase_12 | AC | 151 ms
40,644 KB |
testcase_13 | AC | 68 ms
21,132 KB |
testcase_14 | AC | 63 ms
20,496 KB |
testcase_15 | AC | 75 ms
22,048 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 27 ms
10,880 KB |
testcase_18 | AC | 123 ms
36,412 KB |
testcase_19 | AC | 146 ms
40,012 KB |
testcase_20 | AC | 53 ms
18,144 KB |
testcase_21 | AC | 116 ms
34,756 KB |
testcase_22 | AC | 87 ms
24,092 KB |
testcase_23 | AC | 34 ms
12,096 KB |
testcase_24 | AC | 34 ms
12,372 KB |
testcase_25 | AC | 8 ms
6,944 KB |
testcase_26 | AC | 112 ms
34,532 KB |
testcase_27 | AC | 28 ms
10,880 KB |
testcase_28 | AC | 30 ms
11,392 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 146 ms
39,776 KB |
testcase_31 | AC | 118 ms
35,236 KB |
testcase_32 | AC | 3 ms
6,940 KB |
testcase_33 | AC | 7 ms
6,944 KB |
testcase_34 | AC | 65 ms
21,536 KB |
testcase_35 | AC | 82 ms
22,608 KB |
testcase_36 | AC | 66 ms
21,420 KB |
testcase_37 | AC | 4 ms
6,940 KB |
testcase_38 | AC | 47 ms
13,420 KB |
testcase_39 | AC | 25 ms
8,468 KB |
testcase_40 | AC | 49 ms
13,428 KB |
testcase_41 | AC | 37 ms
12,640 KB |
testcase_42 | AC | 81 ms
22,332 KB |
testcase_43 | AC | 6 ms
6,944 KB |
testcase_44 | AC | 72 ms
22,072 KB |
testcase_45 | AC | 44 ms
13,168 KB |
testcase_46 | AC | 9 ms
6,940 KB |
testcase_47 | AC | 25 ms
8,252 KB |
testcase_48 | AC | 66 ms
21,524 KB |
testcase_49 | AC | 5 ms
6,940 KB |
testcase_50 | AC | 78 ms
22,300 KB |
testcase_51 | AC | 44 ms
13,172 KB |
testcase_52 | AC | 5 ms
6,940 KB |
testcase_53 | AC | 153 ms
40,536 KB |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct SegmentTree { public: int n; vector<ll> node; vector<vector<pair<int, ll>>> g; SegmentTree(vector<ll> v) { int sz = v.size(); n = 1; while (sz > n) n *= 2; } void add_edge(int a, int b, int nd, int len, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return; if (a <= l && r <= b) { g[nd + n - 1].emplace_back(k, len); return; } add_edge(a, b, nd, len, 2 * k + 1, l, (l + r) / 2); add_edge(a, b, nd, len, 2 * k + 2, (l + r) / 2, r); } }; struct technique { ll a, b, c; int id; technique(ll _a, ll _b, ll _c, int _id) :a(_a), b(_b), c(_c), id(_id) {} bool operator <(technique &t) { if (a == t.a) { if (b == t.b) return c < t.c; else return b < t.b; } else return a < t.a; } }; vector<ll> dp; vector<bool> used; vector<technique> vt; vector<int> score; int n; ll dfs(int cur, SegmentTree& seg) { if (dp[cur] != -1) return dp[cur]; if (used[cur]) return dp[cur] = INF; ll res = 0; used[cur] = true; for (auto next : seg.g[cur]) { ll tmp = dfs(next.first, seg); if (tmp == INF) res = INF; else chmax(res, tmp); } if (res == INF) return dp[cur] = INF; return dp[cur] = res + score[cur]; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%d", &n); vector<technique> vt; vt.reserve(n); for (int i = 0; i < n; i++) { ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c); vt.emplace_back(a, b, c, i); } SegmentTree seg(vector<ll>(n,0)); n = seg.n; used = vector<bool>(n * 2, false); seg.g.resize(n * 2); dp = vector<ll>(n * 2, -1); score.resize(n * 2); for (int i = 0; i < n - 1; i++) { seg.g[i].emplace_back(i * 2 + 1, 0); seg.g[i].emplace_back(i * 2 + 2, 0); } sort(vt.begin(), vt.end()); for (int i = 0; i < vt.size(); i++) { score[i + n - 1] = vt[i].b; } for (int i = 0; i < vt.size(); i++) { ll d = vt[i].b - vt[i].c; int left = -1; int right = vt.size(); while (right - left > 1) { int mid = (left + right) >> 1; if (mid == vt.size()) left = mid; else if (d < vt[mid].a) right = mid; else left = mid; } //cout << i << " " << right << endl; if (right == 0) continue; if(right < i) seg.add_edge(0, right, i, 0); else { seg.add_edge(0, i, i, 0); if(i + 1!= right) seg.add_edge(i + 1, right, i, 0); } } vector<ll> ans(vt.size()); for (int i = 0; i < vt.size(); i++) { ans[vt[i].id] = dfs(i + n - 1, seg); } for (int i = 0; i < ans.size(); i++) { if (ans[i] == INF) puts("BAN"); else printf("%lld\n", ans[i]); } return 0; }