/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Wrong Answer 16ms 796.0 KiB
#5 Wrong Answer 3ms 560.0 KiB
#6 Wrong Answer 19ms 536.0 KiB
#7 Accepted 11ms 540.0 KiB
#8 Accepted 16ms 540.0 KiB
#9 Accepted 20ms 536.0 KiB
#10 Accepted 24ms 540.0 KiB
#11 Accepted 21ms 580.0 KiB
#12 Accepted 14ms 540.0 KiB
#13 Wrong Answer 26ms 540.0 KiB
#14 Wrong Answer 26ms 532.0 KiB
#15 Wrong Answer 26ms 772.0 KiB
#16 Wrong Answer 26ms 540.0 KiB
#17 Accepted 26ms 328.0 KiB
#18 Accepted 26ms 540.0 KiB
#19 Accepted 26ms 788.0 KiB
#20 Accepted 26ms 540.0 KiB
#21 Accepted 21ms 540.0 KiB
#22 Accepted 20ms 332.0 KiB
#23 Wrong Answer 14ms 540.0 KiB
#24 Accepted 16ms 540.0 KiB
#25 Wrong Answer 18ms 540.0 KiB
#26 Wrong Answer 2ms 540.0 KiB
#27 Wrong Answer 1ms 540.0 KiB

Code

// BISMILLAH

#include "bits/stdc++.h"

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 200005, inf = 1000000005, bit_len = 60;

signed main() {
    // fastIO;
	int testCases=1;
	// scanf("%lld",&testCases);

    for (int T = 1; T <= testCases; T++) {
        int N;
        ll k;
        scanf("%d%lld", &N, &k);
        int bit[bit_len] = {0};
        for (int i = 0; i < N; i++) {
            ll a;
            scanf("%lld", &a);
            for (int b = 0; b < bit_len; b++) {
                if ((1ll<<b)&a) {
                    bit[b]++;
                }
            }
        }
        int st_bit;
        for (int i = bit_len - 1; i >= 0; i--) {
            if ((1ll<<i)&k) {
                st_bit = i;
                break;
            }
        }
        ll ans = 0;
        for (int i = bit_len - 1; i > st_bit; i--) {
            ans += (1ll << i) * bit[i];
        }
        for (int i = st_bit; i >= 0; i--) {
            if ((1ll<<i)&k) {
                ans += (1ll << i)*std::max(bit[i], N - bit[i]);
            } else {
                ans += (1ll << i) * bit[i];
            }
        }
        printf("%lld\n", ans);
    }
	
	return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1054 Yet another challenge for Roy!
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-07 19:45:43
Judged At
2024-05-07 19:45:43
Judged By
Score
60
Total Time
26ms
Peak Memory
796.0 KiB