Submission #1091672

# Submission time Handle Problem Language Result Execution time Memory
1091672 2024-09-21T18:47:43 Z efishel Xor Sort (eJOI20_xorsort) C++17
25 / 100
87 ms 18540 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

const ll MAXN = 1E3+16;
// ll th[MAXN];
vii ans;
void fop (vll &ve, ll i, ll j) {
    ans.push_back({ i, j });
    ve[i] ^= ve[j];
    // th[i] ^= th[j];
}
void fswap (vll &ve, ll i) { // swap the indices (i, i+1)
    fop(ve, i, i+1);
    fop(ve, i+1, i);
    fop(ve, i, i+1);
}

// void fsolve (vll &ve, ll l, ll r, ll bit) {
//     if (bit == -1 || l > r) return;
//     for (ll i = l; i <= r; i++) th[i] = ve[i]>>bit&1;
//     for (ll i = l; i <= r; i++) {
//         for (ll j = l; j < r; j++) {
//             if (ve[j] > ve[j+1]) {
//                 fswap(ve, j);
//             }
//         }
//     }
//     // ll il = l, ir = r;
//     // while (il < ir) {
//     //     while (il < ir && th[il] == 0) il++;
//     //     while (il < ir && th[ir] == 1) ir--;
//     //     if (il >= ir) break;
//     //     fswap(ve, il, ir);
//     //     il++; ir--;
//     // }
//     for (ll i = l; i <= r; i++) th[i] = ve[i]>>bit&1;
//     // assert(is_sorted(th+l, th+r+1));
//     ll mid = r;
//     while (th[mid] == 1) mid--;
//     fsolve(ve, l, mid, bit-1);
//     fsolve(ve, mid+1, r, bit-1);
// }

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n, s;
    cin >> n >> s;
    vll ve(n);
    for (ll &i : ve) cin >> i;
    for (ll i = 0; i <= n-1; i++) {
        for (ll j = 0; j < n-1; j++) {
            if (ve[j] > ve[j+1]) {
                fswap(ve, j);
            }
        }
    }
    cout << ans.size() << '\n';
    for (auto [i, j] : ans) cout << i+1 << ' ' << j+1 << '\n';
    for (ll i : ve) cerr << i << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 736 KB Output is correct
5 Correct 2 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 2 ms 992 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 3 ms 988 KB Output is correct
10 Correct 2 ms 992 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1496 KB Output is correct
13 Correct 4 ms 1508 KB Output is correct
14 Correct 5 ms 1500 KB Output is correct
15 Correct 5 ms 1500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 736 KB Output is correct
5 Correct 2 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 2 ms 992 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 3 ms 988 KB Output is correct
10 Correct 2 ms 992 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1496 KB Output is correct
13 Correct 4 ms 1508 KB Output is correct
14 Correct 5 ms 1500 KB Output is correct
15 Correct 5 ms 1500 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 992 KB Output is correct
18 Correct 4 ms 1244 KB Output is correct
19 Correct 4 ms 1244 KB Output is correct
20 Correct 4 ms 1244 KB Output is correct
21 Correct 4 ms 1244 KB Output is correct
22 Correct 4 ms 1244 KB Output is correct
23 Correct 4 ms 1240 KB Output is correct
24 Correct 4 ms 1244 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Incorrect 7 ms 1752 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 1244 KB Output is correct
5 Incorrect 87 ms 18540 KB Integer 764742 violates the range [0, 40000]
6 Halted 0 ms 0 KB -