/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 484.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 21ms 1.004 MiB
#5 Accepted 4ms 624.0 KiB
#6 Accepted 26ms 1.031 MiB
#7 Accepted 15ms 792.0 KiB
#8 Accepted 19ms 912.0 KiB
#9 Accepted 27ms 1.062 MiB
#10 Accepted 28ms 1.156 MiB
#11 Accepted 28ms 1.141 MiB
#12 Accepted 18ms 948.0 KiB
#13 Accepted 35ms 1.305 MiB
#14 Accepted 35ms 1.305 MiB
#15 Accepted 35ms 1.305 MiB
#16 Accepted 36ms 1.309 MiB
#17 Accepted 36ms 1.062 MiB
#18 Accepted 36ms 1.062 MiB
#19 Accepted 36ms 1.273 MiB
#20 Accepted 36ms 1.309 MiB
#21 Accepted 29ms 1.164 MiB
#22 Accepted 27ms 1.062 MiB
#23 Accepted 19ms 1.316 MiB
#24 Accepted 20ms 1.062 MiB
#25 Accepted 25ms 1.305 MiB
#26 Accepted 1ms 532.0 KiB
#27 Accepted 1ms 320.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main () {
  cin.tie(0)->sync_with_stdio(0);
  int n, k, ans = 0, sum = 0;
  cin >> n >> k;
  int a[n];
  int bt[42]{};
  int ct[42]{};
  for (int i = 0; i < n; i++) {
      cin >> a[i];
      int pos = 0, cnt = 41;
      while (cnt--) {
          if (a[i]%2 == 0) {
              bt[pos]++;
          }
          else ct[pos]++;
          pos++;
          a[i] /= 2;
      }
  }
  for (int i = 0; i < 42; i++) {
      bt[i] *= (1LL<<i);
      ct[i] *= (1LL<<i);
  }
  for (int i = 41; i >= 0; i--) {
      if ((1LL<<i)&k) {
          int tot = 0;
          for (int j = 0; j < i; j++) {
              tot += max (bt[j], ct[j]);
          }
          ans = max (ans, tot+sum+ct[i]);
          sum += bt[i];
      }
      else sum += ct[i];
  }
  ans = max (ans, sum);
  cout << ans << "\n";
}

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:13:20
Judged At
2024-11-11 03:32:27
Judged By
Score
100
Total Time
36ms
Peak Memory
1.316 MiB