/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 336.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 23ms 836.0 KiB
#5 Accepted 4ms 580.0 KiB
#6 Accepted 27ms 1.062 MiB
#7 Accepted 16ms 836.0 KiB
#8 Accepted 21ms 832.0 KiB
#9 Accepted 29ms 1.02 MiB
#10 Accepted 30ms 1.172 MiB
#11 Accepted 30ms 1.02 MiB
#12 Accepted 20ms 956.0 KiB
#13 Accepted 38ms 1.312 MiB
#14 Accepted 37ms 1.316 MiB
#15 Accepted 38ms 1.312 MiB
#16 Accepted 36ms 1.309 MiB
#17 Accepted 37ms 1.309 MiB
#18 Accepted 36ms 1.312 MiB
#19 Accepted 37ms 1.32 MiB
#20 Accepted 37ms 1.312 MiB
#21 Accepted 30ms 1.168 MiB
#22 Accepted 29ms 1.133 MiB
#23 Accepted 22ms 1.312 MiB
#24 Accepted 17ms 1.105 MiB
#25 Accepted 21ms 1.312 MiB
#26 Accepted 1ms 320.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-11-11 03:31:59
Judged By
Score
100
Total Time
38ms
Peak Memory
1.32 MiB