| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 405700 | radaiosm7 | Xor Sort (eJOI20_xorsort) | C++98 | 12 ms | 1092 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.
#include <bits/stdc++.h>
using namespace std;
int n, cc, s, i, k, curr, j, mx;
vector<pair<int, int> > ans;
int a[1005], b[1005];
bool hasBit;
void oper(int x, int y) {
a[x] ^= a[y];
ans.push_back(make_pair(x,y));
}
int main() {
scanf("%d%d", &n, &s);
for (i=1; i <= n; ++i) {
scanf("%d", &a[i]);
b[i] = a[i];
}
if (s == 1) {
for (i=n; i >= 1; --i) {
for (j=1; j <= min(n-1, i); ++j) {
oper(j, j+1);
}
curr = 1;
for (j=2; j <= i; ++j) {
if (b[j]>b[curr]) {
curr = j;
}
}
for (j=curr-2; j >= 1; --j) {
oper(j, j+1);
}
for (j=curr+1; j <= i; ++j) {
oper(j, j-1);
}
mx = b[curr];
for (j=curr; j < i; ++j) {
b[j] = b[j+1];
}
b[i]=mx;
}
}
else {
for (i=19; i >= 0; --i) {
hasBit = false;
for (j=1; j <= n; ++j) {
if ((a[j]>>i)&1) {
hasBit = true;
}
}
if (hasBit) {
for (j=2; j <= n; ++j) {
if (!((a[j]>>i)&1)) {
oper(j, j-1);
}
}
for (j=1; j < n; ++j) {
if ((a[j]>>i)&1) {
oper(j, j+1);
}
}
--n;
}
}
}
printf("%d\n", (int)ans.size());
for (i=0; i < (int)ans.size(); ++i) {
printf("%d %d\n", ans[i].first, ans[i].second);
}
return 0;
}
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... | ||||
