結果
問題 | No.2957 Combo Deck Builder |
ユーザー | nono00 |
提出日時 | 2024-11-09 01:21:59 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 156 ms / 1,000 ms |
コード長 | 4,634 bytes |
コンパイル時間 | 3,805 ms |
コンパイル使用メモリ | 269,796 KB |
実行使用メモリ | 20,092 KB |
最終ジャッジ日時 | 2024-11-09 01:22:19 |
合計ジャッジ時間 | 10,223 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 156 ms
14,052 KB |
testcase_07 | AC | 124 ms
14,064 KB |
testcase_08 | AC | 124 ms
14,068 KB |
testcase_09 | AC | 119 ms
14,032 KB |
testcase_10 | AC | 145 ms
13,832 KB |
testcase_11 | AC | 119 ms
13,948 KB |
testcase_12 | AC | 117 ms
13,852 KB |
testcase_13 | AC | 119 ms
13,896 KB |
testcase_14 | AC | 119 ms
13,720 KB |
testcase_15 | AC | 121 ms
13,648 KB |
testcase_16 | AC | 122 ms
13,780 KB |
testcase_17 | AC | 123 ms
13,676 KB |
testcase_18 | AC | 122 ms
13,756 KB |
testcase_19 | AC | 121 ms
13,816 KB |
testcase_20 | AC | 119 ms
13,620 KB |
testcase_21 | AC | 120 ms
13,768 KB |
testcase_22 | AC | 120 ms
13,760 KB |
testcase_23 | AC | 120 ms
13,644 KB |
testcase_24 | AC | 120 ms
13,588 KB |
testcase_25 | AC | 121 ms
13,768 KB |
testcase_26 | AC | 143 ms
19,908 KB |
testcase_27 | AC | 139 ms
20,092 KB |
testcase_28 | AC | 142 ms
19,828 KB |
testcase_29 | AC | 137 ms
19,832 KB |
testcase_30 | AC | 85 ms
17,204 KB |
testcase_31 | AC | 73 ms
14,260 KB |
testcase_32 | AC | 77 ms
10,228 KB |
testcase_33 | AC | 124 ms
19,944 KB |
testcase_34 | AC | 66 ms
8,064 KB |
testcase_35 | AC | 67 ms
8,064 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; template <class T> using max_heap = priority_queue<T>; template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>; #define rep(i, l, r) for (ll i = (l); i < (r); i++) #define rrep(i, r, l) for (ll i = (r); i-- > (l);) #define all(x) begin(x), end(x) template <class T> bool chmin(T& lhs, T rhs) { return lhs > rhs ? (lhs = rhs, true) : false; } template <class T> bool chmax(T& lhs, T rhs) { return lhs < rhs ? (lhs = rhs, true) : false; } struct IOIO { IOIO() { cin.tie(0)->sync_with_stdio(0); } } ioio; template <class S, class T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& vs) { os << '{'; rep(i, 0, (int)vs.size()) os << vs[i] << (i + 1 == (int)vs.size() ? "" : ", "); os << '}'; return os; } template <class T> ostream& operator<<(ostream& os, const set<T>& vs) { os << '{'; for (auto it = vs.begin(); it != vs.end(); it++) { if (it != vs.begin()) { os << ", "; } os << *it; } os << '}'; return os; } template <class T, class U> ostream& operator<<(ostream& os, const map<T, U>& vs) { os << '{'; for (auto it = vs.begin(); it != vs.end(); it++) { if (it != vs.begin()) { os << ", "; } os << *it; } os << '}'; return os; } #ifdef DEBUG void dump_func() { cerr << endl; } template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { cerr << head; if (sizeof...(Tail) > 0) { cerr << ", "; } dump_func(std::move(tail)...); } #define dump(...) cerr << "[" + string(#__VA_ARGS__) + "] ", dump_func(__VA_ARGS__) #else #define dump(...) static_cast<int>(0) #endif void solve() { int n; cin >> n; struct Card { int i; int c; ll x, y; }; vector<Card> cards(n); rep(i, 0, n) cin >> cards[i].c >> cards[i].x >> cards[i].y, cards[i].i = i; ll ans = 0; for (auto& card: cards) { ll mn = min(card.x, card.y); ans += mn; card.x -= mn; card.y -= mn; } vector<char> used(n); const char X = 'X'; const char Y = 'Y'; dump(used); { min_heap<pair<ll, int>> que; vector<Card> a; for (auto card: cards) if (card.x < card.y) a.push_back(card); sort(all(a), [](auto lhs, auto rhs) { return lhs.c < rhs.c; }); rep(i, 0, ssize(a)) { que.emplace(a[i].y, a[i].i); if (que.size() > a[i].c) { que.pop(); } } while (!que.empty()) { auto [y, i] = que.top(); que.pop(); ans += y; used[i] = Y; } rep(i, 0, ssize(a)) { if (used[a[i].i] == 0) { used[a[i].i] = X; ans += a[i].x; } } } dump(used); { min_heap<pair<int, int>> que; for (auto card: cards) { if (card.x == card.y) { ans += card.x; used[card.i] = Y; } else if (card.x > card.y) { que.emplace(card.c, card.i); } } int used_num = n - count(all(used), 0); while (!que.empty()) { auto [c, i] = que.top(); if (c <= used_num) { que.pop(); ans += cards[i].x; used[i] = X; used_num++; } else { break; } } } dump(used); { min_heap<pair<ll, int>> que; vector<Card> a; rep(i, 0, n) if (used[i] == 0) { auto card = cards[i]; card.c = n - card.c; a.push_back(card); } sort(all(a), [](auto lhs, auto rhs) { return lhs.c < rhs.c; }); rep(i, 0, ssize(a)) { que.emplace(a[i].x, a[i].i); if (que.size() > a[i].c) { que.pop(); } } while (!que.empty()) { auto [x, i] = que.top(); que.pop(); ans += x; used[i] = X; } rep(i, 0, ssize(a)) { if (used[a[i].i] == 0) { used[a[i].i] = Y; ans += a[i].y; } } } dump(used); cout << ans << '\n'; } int main() { int t = 1; while (t--) solve(); }