# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1089731 | vjudge1 | Xor Sort (eJOI20_xorsort) | C++17 | 6 ms | 1056 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* https://oj.uz/problem/view/eJOI20_xorsort?locale=en: WA */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <limits.h>
unsigned int N, S, A[1000];
std::vector<std::pair<unsigned int, unsigned int>> operations;
void destroysort(void) {
unsigned int i, j, mask;
for (j = N; j > 1; --j) {
if (j == 0) return;
mask = 0;
for (i = 0; i < j; ++i)
mask |= A[i];
if (mask == 0) return;
mask = 1 << (sizeof(mask) * CHAR_BIT - __builtin_clz(mask) - 1);
for (i = 0; i < j - 1; ++i) {
if (A[i] & mask) {
if (!(A[i+1] & mask)) {
A[i+1] ^= A[i];
operations.push_back({i+1, i});
}
A[i] ^= A[i+1];
operations.push_back({i, i+1});
}
}
}
}
void cursedbubblesort(void) {
unsigned int i, j, k;
for (j = N; j > 1; --j) {
k = 0;
for (i = 1; i < j; ++i)
if (A[i] > A[k])
k = i;
if (k == j-1) {
operations.push_back({j-2, j-1});
} else {
for (i = k; i < j - 1; ++i)
operations.push_back({i+1, i});
for (i = k; i > 1; --i)
operations.push_back({i-2, i-1});
for (i = 0; i < j - 1; ++i)
operations.push_back({i, i+1});
memmove(&A[k], &A[k+1], sizeof(*A)*(j-k-1));
}
}
}
int main(void) {
(void) scanf("%u %u", &N, &S);
for (unsigned int i = 0; i < N; ++i)
(void) scanf(" %u", &A[i]);
if (S == 1) {
for (unsigned int i = 0; i < N - 1; ++i)
operations.push_back({i, i+1});
cursedbubblesort();
} else {
destroysort();
}
printf("%u\n", operations.size());
for (auto operation : operations)
printf("%u %u\n", operation.first + 1, operation.second + 1);
return EXIT_SUCCESS;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |