답안 #1091671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091671 2024-09-21T18:46:27 Z efishel Xor Sort (eJOI20_xorsort) C++17
25 / 100
87 ms 18528 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;
    fsolve(ve, 0, n-1, 19);
    cout << ans.size() << '\n';
    for (auto [i, j] : ans) cout << i+1 << ' ' << j+1 << '\n';
    // for (ll i : ve) cerr << i << ' ';
    return 0;
}


/*

3, 2
3, 1
2, 1
2, 3
1, 3

2, 2

 */
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 3 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 3 ms 988 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 3 ms 992 KB Output is correct
10 Correct 2 ms 992 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1500 KB Output is correct
13 Correct 4 ms 1752 KB Output is correct
14 Correct 4 ms 1500 KB Output is correct
15 Correct 4 ms 1500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 3 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 3 ms 988 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 3 ms 992 KB Output is correct
10 Correct 2 ms 992 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1500 KB Output is correct
13 Correct 4 ms 1752 KB Output is correct
14 Correct 4 ms 1500 KB Output is correct
15 Correct 4 ms 1500 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 2 ms 992 KB Output is correct
18 Correct 5 ms 1240 KB Output is correct
19 Correct 4 ms 1256 KB Output is correct
20 Correct 3 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 1244 KB Output is correct
24 Correct 4 ms 1240 KB Output is correct
25 Correct 4 ms 1244 KB Output is correct
26 Incorrect 7 ms 1820 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 18528 KB Integer 764742 violates the range [0, 40000]
6 Halted 0 ms 0 KB -