/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 308.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Wrong Answer 11ms 836.0 KiB
#5 Wrong Answer 3ms 516.0 KiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n;
  int64_t k;
  cin >> n >> k;
  vector<int64_t> a(n);
  for (int64_t &i : a) cin >> i;
  int l = __lg(k);
  vector<int> cnt(l + 1, 0);
  for (int i = 0; i <= l; i++) {
    for (auto it : a) {
      if (it >> i & 1) cnt[i] -= 1;
      else cnt[i] += 1;
    }
  }
  int64_t p = 0;
  bool done = false;
  for (int i = 0; i <= l; i++) {
    if (cnt[i] > 0) {
      if (k >> i & 1) {
        p |= (1 << i);
      } else if (done) {
        p |= (1 << i);
      }
    } else if (p >> i & 1) {
      done = 1;
    }
  }
  int64_t ans = 0;
  for (auto it : a) ans += it ^ p;
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  // cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1054 Yet another challenge for Roy!
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 09:49:44
Judged At
2024-11-11 03:26:16
Judged By
Score
3
Total Time
11ms
Peak Memory
836.0 KiB