/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Wrong Answer 1ms 320.0 KiB
#4 Wrong Answer 24ms 1.012 MiB

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;
  vector<vector<int64_t>> dp(41, vector<int64_t>(2,0));
  for (int i = 0; i < 41; i++) {
    for (auto it : a) {
      if (it >> i & 1) {
        dp[i][0] += 1 << i;
      } else {
        dp[i][1] += 1 << i;
      }
    }
  }
  int64_t res = 0, sum = 0;
  for (int i = 40; ~i; --i) {
    if (k >> i & 1) {
      int64_t now = sum + dp[i][0];
      for (int j = i - 1; ~j; j--) {
        now += max(dp[j][0], dp[j][1]);
      }
      res = max(res, now);
      sum += dp[i][1];
    } else {
      sum += dp[i][0];
    }
  }
  cout << max(sum, res) << "\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 11:13:38
Judged At
2024-11-11 03:26:16
Judged By
Score
2
Total Time
24ms
Peak Memory
1.012 MiB