70分求调
查看原帖
70分求调
1726629
liu_rui_xuan329楼主2025/8/5 10:28
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
long long C1, C2;
map<int, int> value;
bool match[N];
int n,a[N],opl;
int count(int x) {
    int count = 0;
    while (x) {
        count += x & 1;
        x >>= 1;
    }
    return count;
}
int main() {
    cin >> n;
    cin >> C1 >> C2;
    for (int i = 0; i < n; ++i) cin >> a[i];
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (C1 >= C2) {
        cout << (n - 1) * C2 << endl;
        return 0;
    }
    for (int i = 0; i < n; ++i) value[a[i]] = i;
    for (int i = 0; i < n; ++i) {
        if (!match[i]) {
            int x = a[i];
            for (int bit = 0; bit < 30; ++bit) {
                int flag = x ^ (1 << bit);
                if (value.find(flag) != value.end()) {
                    int j = value[flag];
                    if (!match[j]) {
                        match[i] = true;
                        match[j] = true;
                        opl++;
                        break;
                    }
                }
            }
        }
    }

    long long total = opl * C1 + (n - 1 - opl) * C2;
    cout << total << endl;
    return 0;
}
2025/8/5 10:28
加载中...