QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276304#6521. Swapping Operationucup-team1321WA 11ms3548kbC++232.2kb2023-12-05 19:38:332023-12-05 19:38:33

Judging History

你现在查看的是最新测评结果

  • [2023-12-05 19:38:33]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3548kb
  • [2023-12-05 19:38:33]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (auto i = 0; i < a; i++)
#define rep2(i, a) for (auto i = 0; i < a; i++)
#define rep3(i, a, b) for (auto i = a; i < b; i++)
#define rep4(i, a, b, c) for (auto i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

const int U = (1 << 30) - 1;
void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vi pre(n + 1), suf(n + 1);
  auto solve = [&]() {
    pre[0] = U;
    rep(i, n) pre[i + 1] = pre[i] & a[i];
    suf[n] = U;
    for (int i = n - 1; i >= 0; i--)
      suf[i] = suf[i + 1] & a[i];
    ll ans = 0;
    rep(i, 1, n) cmax(ans, pre[i] + suf[i]);
    return ans;
  };
  auto get_ans = [&](int x, int y) {
    swap(a[x], a[y]);
    ll res = solve();
    swap(a[x], a[y]);
    return res;
  };

  ll ans = solve();

  vi p;
  int x = U;
  rep(i, n) if ((x & a[i]) < x) {
    p.pb(i);
    x &= a[i];
  }

  x = U;
  for (int i = n - 1; i >= 0; i--)
    if ((x & a[i]) < x) {
      p.pb(i);
      x &= a[i];
    }

  sort(all(p));
  p.resize(unique(all(p)) - p.begin());
  rep(i, p.size()) {
    rep(j, i + 1, p.size()) { cmax(ans, get_ans(p[i], p[j])); }
  }

  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

3
6
6 5 4 3 5 6
6
1 2 1 1 2 2
5
1 1 2 2 2

output:

7
3
3

result:

ok 3 number(s): "7 3 3"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3516kb

input:

1000
100
803046221 177233942 164782937 53823867 383853667 250036100 888743479 576687945 737272231 801579441 647643785 393059353 401516062 663466861 308544510 825328494 162739603 501761995 570908380 655227403 444493122 844535039 208303132 493226172 421479971 634680694 396627047 787471115 335787136 16...

output:

890299519
923642535
960163633
963497255
906186590
923065154
979836345
771417883
973791353
897446548
920223968
969979000
494498965
917264022
981686922
827513928
988685740
989181315
729655322
863912714
968789214
934333526
924124296
964130484
971937793
918136308
977368039
980800625
551789116
973760189
...

result:

wrong answer 1st numbers differ - expected: '999397418', found: '890299519'