# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501666 | LucaIlie | Xor Sort (eJOI20_xorsort) | C++17 | 6 ms | 972 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 <iostream>
#define MAX_N 1000
#define MAX_K 40000
using namespace std;
struct answer {
int x, y;
};
int v[MAX_N + 1];
answer ans[MAX_K];
int main() {
int n, s, k, i, j, p;
cin >> n >> s;
for ( i = 1; i <= n; i++ )
cin >> v[i];
k = 0;
for ( i = 1; i <= n; i++ ) {
for ( j = 1; j <= n - 1; j++ ) {
if ( v[j] > v[j + 1] ) {
ans[k] = { j, j + 1 };
v[j] ^= v[j + 1];
ans[k + 1] = { j + 1, j };
v[j + 1] ^= v[j];
ans[k + 2] = { j, j + 1 };
v[j] ^= v[j + 1];
k += 3;
}
}
}
cout << k << "\n";
for ( i = 0; i < k; i++ )
cout << ans[i].x << " " << ans[i].y << "\n";
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... |