ABC F 求调
  • 板块题目总版
  • 楼主Garbage_fish
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/2/1 21:53
  • 上次更新2025/2/2 13:15:26
查看原帖
ABC F 求调
298424
Garbage_fish楼主2025/2/1 21:53

发错板块了(

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e5 + 10, base = 1331, mod = 1e9 + 7;
int n, k, a[N], b[N], c[N];
unordered_map<int, bool> mp;
bool cmp(int x, int y) {
    return x > y;
}
void init(int a[]) {
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + n + 1, cmp);
}
int query(int i, int j, int k) {
    return a[i] * b[j] + b[j] * c[k] + c[k] * a[i];
}
struct node {
    int ca, cb, cc;
    bool operator<(const node &tmp) const {
        return query(ca, cb, cc) != query(tmp.ca, tmp.cb, tmp.cc) ? query(ca, cb, cc) < query(tmp.ca, tmp.cb, tmp.cc) : (ca != tmp.ca ? ca < tmp.ca : (cb != tmp.cb ? cb < tmp.cb : cc < tmp.cc));
    }
};
priority_queue<node> q;
signed main() {
    IOS;
    cin >> n >> k;
    init(a), init(b), init(c);
    q.push({1, 1, 1});
    for (int i = 1; i < k; i++) {
        auto [ca, cb, cc] = q.top();
        q.pop();
        while (!q.empty()) {
            auto [x, y, z] = q.top();
            if (x != ca or y != cb or z != cc)
                break;
            q.pop();
        }
        if (ca < n)
            q.push({ca + 1, cb, cc});
        if (cb < n)
            q.push({ca, cb + 1, cc});
        if (cc < n)
            q.push({ca, cb, cc + 1});
    }
    auto [ca, cb, cc] = q.top();
    cout << query(ca, cb, cc);
    return 0;
}

ca/cb/ccca/cb/cc 是下标,query 是算这三个下标的答案,优先队列比较函数写一大串是为了去重。

2025/2/1 21:53
加载中...