/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 21ms 832.0 KiB
#5 Accepted 4ms 580.0 KiB
#6 Accepted 25ms 1.066 MiB
#7 Accepted 15ms 876.0 KiB
#8 Accepted 19ms 984.0 KiB
#9 Accepted 27ms 1.145 MiB
#10 Accepted 27ms 1.246 MiB
#11 Accepted 27ms 1.062 MiB
#12 Accepted 18ms 836.0 KiB
#13 Accepted 34ms 1.32 MiB
#14 Accepted 34ms 1.316 MiB
#15 Accepted 34ms 1.309 MiB
#16 Accepted 34ms 1.312 MiB
#17 Accepted 34ms 1.066 MiB
#18 Accepted 34ms 1.309 MiB
#19 Accepted 34ms 1.312 MiB
#20 Accepted 34ms 1.316 MiB
#21 Accepted 28ms 1.156 MiB
#22 Accepted 26ms 1.066 MiB
#23 Accepted 16ms 1.27 MiB
#24 Accepted 13ms 1.27 MiB
#25 Accepted 15ms 1.117 MiB
#26 Wrong Answer 1ms 320.0 KiB
#27 Wrong Answer 1ms 324.0 KiB

Code


#include <bits/stdc++.h>

#ifdef LOCAL
#include "../algo/debug.h"
#else 
#define debug(...) 0
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0, w = 0;
  for (int b = 40; b >= 0; b--) {
    long long now[2] {};
    for (int i = 0; i < n; i++) {
      if (a[i] >> b & 1) {
        now[0] += 1ll << b;
      } else {
        now[1] += 1ll << b;
      }
    }
    if (w + (1ll << b) <= k) {
      if (now[1] > now[0]) {
        w += 1ll << b;
        ans += now[1];
      } else {
        ans += now[0];
      }
    } else {
      ans += now[0];
    }
  }
  cout << ans << '\n';
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1054 Yet another challenge for Roy!
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 17:31:17
Judged At
2024-10-03 13:48:31
Judged By
Score
98
Total Time
34ms
Peak Memory
1.32 MiB