WA*1 求调
查看原帖
WA*1 求调
726862
zhanglh楼主2025/2/6 23:26

WA on test 47

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
ll a[500010], b[500010], c[500010];
map<ll, bool> vis;

struct Node {
    ll val; int x, y, z;
    bool operator <(const Node &W)const {
        return val < W.val;
    }
};
priority_queue<Node, vector<Node>, less<Node> > q;

bool cmp(ll a, ll b) { return a > b; }

ll get(ll i, ll j, ll k) {
    return ((i * n) + j) * n + k;
}

ll calc(int i, int j, int k) {
    return a[i] * b[j] + b[j] * c[k] + c[k] * a[i];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    
    if (m == 1) {
        cout << calc(1, 1, 1) << "\n";
        return 0;
    }
    
    sort(a + 1, a + n + 1, cmp);
    sort(b + 1, b + n + 1, cmp);
    sort(c + 1, c + n + 1, cmp);
    
    m--;
    q.push({calc(1, 1, 1), 1, 1, 1});
    vis[get(1, 1, 1)] = true;
    while(m--) {
        auto t = q.top();
        q.pop();
        int i = t.x, j = t.y, k = t.z;
        if (vis[get(i + 1, j, k)] == false && i < n) {
            q.push({calc(i + 1, j, k), i + 1, j, k});
            vis[get(i + 1, j, k)] = true;
        }
        if (vis[get(i, j + 1, k)] == false && j < n) {
            q.push({calc(i, j + 1, k), i, j + 1, k});
            vis[get(i, j + 1, k)] = true;
        }
        if (vis[get(i, j, k + 1)] == false && k < n) {
            q.push({calc(i, j, k + 1), i, j, k + 1});
            vis[get(i, j, k + 1)] = true;
        }
    }
    
    cout << q.top().val << "\n";
    
    return 0;
}

2025/2/6 23:26
加载中...