QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#366647 | #7937. Fast XORting | milmillin | WA | 51ms | 5260kb | C++14 | 1.6kb | 2024-03-25 06:04:36 | 2024-03-25 06:04:36 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> tbl(n);
vector<int> tmp(n);
for (int i = 0; i < n; i++) {
scanf("%d", &tbl[i]);
}
int l = 0;
while ((1 << l) < n) l++;
long long ans0 = 0;
long long ans1 = 0;
for (int k = l; k > 0; k--) {
int mask = (1 << k) - 1;
int bitsel = (1 << (k - 1));
long long shift0 = 0;
long long shift1 = 0;
int cnt0 = 0;
int cnt1 = 0;
for (int i = 0; i < n; i++) {
int im = i & mask;
if (im == 0) {
cnt0 = cnt1 = 0;
}
if (tbl[i] & bitsel) {
// printf("1 %d: %d\n", tbl[i], im - cnt1);
shift1 += im - cnt1;
cnt1++;
} else {
// printf("0 %d: %d\n", tbl[i], im - cnt0);
shift0 += im - cnt0;
cnt0++;
}
}
ans1 = min(ans0, ans1) + shift1;
ans0 += shift0;
cnt0 = 0;
cnt1 = bitsel;
for (int i = 0; i < n; i++) {
int im = i & mask;
if (im == 0) {
cnt0 = 0;
cnt1 = bitsel;
}
if (tbl[i] & bitsel) {
tmp[i - im + cnt1] = tbl[i];
cnt1++;
} else {
tmp[i - im + cnt0] = tbl[i];
cnt0++;
}
}
swap(tbl, tmp);
}
printf("%lld\n", min(ans0, ans1 + 1));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
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: 3780kb
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: 51ms
memory: 5260kb
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:
17140194151
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '17140194151'