/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 536.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 22ms 1.008 MiB
#5 Accepted 4ms 620.0 KiB
#6 Accepted 27ms 1.246 MiB
#7 Accepted 16ms 876.0 KiB
#8 Accepted 21ms 736.0 KiB
#9 Accepted 28ms 1.102 MiB
#10 Accepted 29ms 1.172 MiB
#11 Accepted 28ms 1.066 MiB
#12 Accepted 18ms 788.0 KiB
#13 Accepted 35ms 1.312 MiB
#14 Accepted 36ms 1.316 MiB
#15 Accepted 36ms 1.066 MiB
#16 Accepted 35ms 1.27 MiB
#17 Accepted 35ms 1.316 MiB
#18 Accepted 36ms 1.316 MiB
#19 Accepted 36ms 1.27 MiB
#20 Accepted 36ms 1.316 MiB
#21 Accepted 29ms 1.176 MiB
#22 Accepted 28ms 1.133 MiB
#23 Accepted 18ms 1.316 MiB
#24 Accepted 14ms 1.27 MiB
#25 Accepted 16ms 1.27 MiB
#26 Wrong Answer 1ms 324.0 KiB
#27 Wrong Answer 1ms 532.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-11-11 03:32:10
Judged By
Score
98
Total Time
36ms
Peak Memory
1.316 MiB