답안 #457989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
457989 2021-08-07T17:23:21 Z RaresFelix Xor Sort (eJOI20_xorsort) C++17
40 / 100
14 ms 5188 KB
#include <bits/stdc++.h>
#define MN 10071
#define ML 20
using namespace std;
int n, s, A[MN];
int F[(1<<21)];
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){
        int nr = 1;
        while(nr){
            nr = 0;
            for(int j = n; j >= 2; --j)
                if(A[j] < A[j-1]){
                    ++nr;
                    if(F[A[j] ^ A[j-1]] || (A[j] ^ A[j-1]) > A[j]){
                        xo(j, j-1);
                        xo(j-1, j);
                        xo(j, j-1);
                    }
                    else {
                        xo(j-1, j);
                    }
                }
        }
    } 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Incorrect 13 ms 5188 KB Integer 45774 violates the range [0, 40000]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Incorrect 13 ms 5188 KB Integer 45774 violates the range [0, 40000]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 3 ms 2508 KB Output is correct
5 Correct 9 ms 4584 KB Output is correct
6 Correct 9 ms 4644 KB Output is correct
7 Correct 9 ms 4680 KB Output is correct
8 Correct 9 ms 4620 KB Output is correct
9 Correct 9 ms 4660 KB Output is correct
10 Correct 11 ms 4696 KB Output is correct
11 Correct 9 ms 4036 KB Output is correct
12 Correct 9 ms 4424 KB Output is correct
13 Correct 14 ms 4296 KB Output is correct
14 Correct 10 ms 4424 KB Output is correct
15 Correct 10 ms 1220 KB Output is correct