QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632532#7937. Fast XORtingForever_Young#WA 139ms48408kbC++201.0kb2024-10-12 13:31:392024-10-12 13:31:39

Judging History

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

  • [2024-10-12 13:31:39]
  • 评测
  • 测评结果:WA
  • 用时:139ms
  • 内存:48408kb
  • [2024-10-12 13:31:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using LL = long long;

int n;

LL solve(vector<vector<int>>& a, bool rev, int dep) {
  if (dep == -1) {
    return 0;
  }
  vector<vector<int>> next_a;
  LL ret = 0;
  for (auto& seg : a) {
    vector<int> v1, v0;
    LL cnt = 0;
    for (auto& v : seg) {
      if (v & (1 << dep)) {
        v1.push_back(v);
        cnt++;
      } else {
        v0.push_back(v);
        ret += cnt;
      }
    }
    next_a.push_back(v0);
    next_a.push_back(v1);
  }
  LL total_pair = 1LL * n * (a[0].size() - 1) / 2;
  if (rev) {
    ret = min(ret, total_pair - ret);
  }
  ret += solve(next_a, rev, dep - 1);
  return ret;
}

int main() {
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int p = 0;
  while ((1 << p) < n) {
    p++;
  }
  vector<vector<int>> b;
  b.push_back(a);
  LL ans = solve(b, true, p - 1) + 1;
  ans = min(ans, solve(b, false, p - 1));
  printf("%lld\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
0 1 3 2 5 4 7 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

8
2 0 1 3 4 5 6 7

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 139ms
memory: 48408kb

input:

262144
47482 131703 90418 122675 166494 247529 196154 16950 66501 50357 246808 25929 10418 50538 26955 151884 63776 58023 20073 26544 74785 44064 41836 148543 87920 54172 3270 131495 130960 112122 167229 215767 77499 195004 21391 11039 168999 256346 109690 180904 172679 157200 78594 201857 52784 147...

output:

17145325034

result:

wrong answer 1st numbers differ - expected: '17137565829', found: '17145325034'