/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 320.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 51ms 888.0 KiB
#5 Accepted 7ms 532.0 KiB
#6 Accepted 55ms 1.02 MiB
#7 Accepted 29ms 852.0 KiB
#8 Accepted 39ms 864.0 KiB
#9 Accepted 80ms 1.035 MiB
#10 Accepted 87ms 1.066 MiB
#11 Accepted 56ms 1.02 MiB
#12 Accepted 35ms 876.0 KiB
#13 Accepted 69ms 1.27 MiB
#14 Accepted 94ms 1.117 MiB
#15 Accepted 74ms 1.078 MiB
#16 Accepted 73ms 1.27 MiB
#17 Accepted 84ms 1.27 MiB
#18 Accepted 84ms 1.066 MiB
#19 Accepted 93ms 1.062 MiB
#20 Accepted 78ms 1.062 MiB
#21 Accepted 61ms 1.133 MiB
#22 Accepted 76ms 1.02 MiB
#23 Accepted 60ms 1.18 MiB
#24 Accepted 42ms 1.066 MiB
#25 Accepted 67ms 1.27 MiB
#26 Wrong Answer 1ms 532.0 KiB
#27 Wrong Answer 1ms 532.0 KiB

Code

#include <iostream>
using namespace std;

const int MAX_N = 100005;
long long A[MAX_N];

int main() {
    int N;
    long long K;
    cin >> N >> K;

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    long long bitCount[45] = {0};

    for (int i = 0; i < N; ++i) {
        for (int b = 0; b < 45; ++b) {
            if ((A[i] >> b) & 1) {
                bitCount[b]++;
            }
        }
    }

    long long bestX = 0;
    for (int b = 44; b >= 0; --b) {
        long long tempX = bestX | (1LL << b);
        if (tempX > K) continue;

        long long ones = bitCount[b];
        long long zeros = N - ones;

        if (zeros > ones) {
            bestX = tempX;
        }
    }

    long long result = 0;
    for (int i = 0; i < N; ++i) {
        result += (A[i] ^ bestX);
    }

    cout << result << endl;
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1054 Yet another challenge for Roy!
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 11:53:41
Judged At
2025-06-13 11:53:41
Judged By
Score
98
Total Time
94ms
Peak Memory
1.27 MiB