/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 1ms 544.0 KiB
#3 Accepted 1ms 408.0 KiB
#4 Accepted 22ms 1.012 MiB
#5 Accepted 4ms 624.0 KiB
#6 Accepted 27ms 1.109 MiB
#7 Accepted 15ms 836.0 KiB
#8 Accepted 20ms 988.0 KiB
#9 Accepted 28ms 1.148 MiB
#10 Accepted 29ms 1000.0 KiB
#11 Accepted 28ms 1.148 MiB
#12 Accepted 19ms 952.0 KiB
#13 Accepted 36ms 1.316 MiB
#14 Accepted 36ms 1.312 MiB
#15 Accepted 35ms 1.316 MiB
#16 Accepted 35ms 1.32 MiB
#17 Accepted 35ms 1.316 MiB
#18 Accepted 35ms 1.309 MiB
#19 Accepted 35ms 1.312 MiB
#20 Accepted 35ms 1.086 MiB
#21 Accepted 29ms 960.0 KiB
#22 Accepted 28ms 1.133 MiB
#23 Accepted 21ms 1.32 MiB
#24 Accepted 17ms 1.312 MiB
#25 Accepted 20ms 1.281 MiB
#26 Accepted 1ms 452.0 KiB
#27 Accepted 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];
  }
  vector now(2, vector<long long> (41));
  for (int b = 40; b >= 0; b--) {
    for (int i = 0; i < n; i++) {
      if (a[i] >> b & 1) {
        now[0][b] += 1ll << b;
      } else {
        now[1][b] += 1ll << b;
      }
    }
  }
  long long sum = 0, ans = 0;
  for (int i = 40; i >= 0; i--) {
    if (k >> i & 1) {
      long long p = sum + now[0][i];
      for (int j = i - 1; j >= 0; j--) {
        p += max(now[0][j], now[1][j]);
      }
      ans = max(ans, p);
      sum += now[1][i];
    } else {
      sum += now[0][i];
    }
  }
  ans = max(ans, sum);
  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:43:07
Judged At
2024-10-03 13:48:06
Judged By
Score
100
Total Time
36ms
Peak Memory
1.32 MiB