結果

問題 No.2957 Combo Deck Builder
ユーザー nono00nono00
提出日時 2024-11-09 01:15:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,701 bytes
コンパイル時間 4,135 ms
コンパイル使用メモリ 269,808 KB
実行使用メモリ 20,020 KB
最終ジャッジ日時 2024-11-09 01:16:09
合計ジャッジ時間 11,481 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 3 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 154 ms
15,076 KB
testcase_07 AC 140 ms
14,956 KB
testcase_08 AC 137 ms
15,084 KB
testcase_09 AC 140 ms
14,952 KB
testcase_10 AC 136 ms
14,856 KB
testcase_11 AC 183 ms
15,040 KB
testcase_12 AC 132 ms
15,004 KB
testcase_13 AC 136 ms
15,168 KB
testcase_14 AC 128 ms
14,736 KB
testcase_15 AC 127 ms
14,668 KB
testcase_16 AC 127 ms
14,800 KB
testcase_17 AC 129 ms
14,824 KB
testcase_18 AC 123 ms
14,904 KB
testcase_19 AC 154 ms
14,968 KB
testcase_20 AC 124 ms
14,764 KB
testcase_21 AC 127 ms
14,788 KB
testcase_22 AC 125 ms
14,788 KB
testcase_23 AC 125 ms
14,792 KB
testcase_24 AC 122 ms
14,732 KB
testcase_25 AC 124 ms
14,916 KB
testcase_26 AC 140 ms
19,908 KB
testcase_27 AC 138 ms
19,988 KB
testcase_28 AC 142 ms
19,952 KB
testcase_29 AC 135 ms
20,020 KB
testcase_30 WA -
testcase_31 AC 71 ms
14,392 KB
testcase_32 AC 114 ms
19,936 KB
testcase_33 AC 121 ms
19,936 KB
testcase_34 AC 65 ms
8,064 KB
testcase_35 AC 67 ms
8,192 KB
testcase_36 WA -
testcase_37 AC 2 ms
5,248 KB
testcase_38 AC 2 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
        vector<Card> a;
        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;
            }
        }
    }
    assert((int)count(all(used), 0) == 0);
    dump(used);
    cout << ans << '\n';
}

int main() {
    int t = 1;

    while (t--) solve();
}
0