Submission #457956

# Submission time Handle Problem Language Result Execution time Memory
457956 2021-08-07T15:43:16 Z RaresFelix Xor Sort (eJOI20_xorsort) C++17
0 / 100
833 ms 524292 KB
#include <bits/stdc++.h>
#define MN 10071
#define ML 20
using namespace std;
int n, s, A[MN];
int F[(1<<20)];
vector<pair<int, int> > SOL;
void xo(int a, int b) {
    --F[A[a]];
    A[a] ^= A[b];
    ++F[A[a]];
    SOL.push_back({a, b});
}
int main() {
    cin >> n >> s;
    for(int i = 1; i <= n; ++i)
        cin >> A[i];
    if(s == 1 || n <= ML){
        for(int i = 1; i <= n; ++i)
            for(int j = n; j >= 2; --j)
                if(A[j] < A[j-1]){
                    if(F[A[j] ^ A[j-1]]){
                        xo(j, j-1);
                        xo(j-1, j);
                        xo(j, j-1);
                    }
                    else {
                        if((A[j] ^ A[j-1]) < A[j])
                            xo(j-1, j);
                        else{
                            xo(j, j-1);
                            j = min(n+1, j+2);
                        }
                    }
                }
    } else {
        for(int j = (ML-1); j >= 0; --j){
            for(int i = 1; i < n + j - (ML-1); ++i){
                if((A[i] & (1<<j)) && A[i+1] & (1<<j)) xo(i, i + 1);
                else if((A[i] & (1<<j))){
                    xo(i+1, i);
                    xo(i, i + 1);
                }
            }
        }
    }
//    for(int i = 1; i <= n; ++i)
//        cout << A[i] << " \n"[i==n];
    cout << SOL.size() << "\n";
    for(auto it : SOL) cout << it.first << " " << it.second << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 778 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 778 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Runtime error 833 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -