답안 #465591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465591 2021-08-16T13:14:48 Z kilikuma Xor Sort (eJOI20_xorsort) C++14
65 / 100
11 ms 1272 KB
#include <bits/stdc++.h>
 
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
 
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, S;
    std::cin >> n >> S;
    
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    std::vector<std::pair<int, int>> ans;
        
    if (S == 1) {
        auto swap = [&](int i, int j) {
            ans.emplace_back(i, j);
            ans.emplace_back(j, i);
            ans.emplace_back(i, j);
            a[i] ^= a[j];
            a[j] ^= a[i];
            a[i] ^= a[j];
        };
        while (!std::is_sorted(a.begin(), a.end())) {
            for (int j = 1; j < n; j++) {
                if (a[j - 1] > a[j]) {
                    swap(j - 1, j);
                }
            }
        }
    } else {
        auto swap = [&](int i, int j) {
            ans.emplace_back(i, j);
            ans.emplace_back(j, i);
            a[i] ^= a[j];
            a[j] ^= a[i];
        };
        for (int i = 19; i >= 0; i--) {
            for (int j = 0; j < n - 1; j++) {
                if (a[j] >> i & 1) {
                    if (a[j + 1] >> i & 1) {
                        ans.emplace_back(j, j + 1);
                        a[j] ^= a[j + 1];
                    } else {
                        swap(j + 1, j);
                    }
                }
            }
            if (a[n - 1] >> i & 1) n--;
        }
    }
    
    std::cout << ans.size() << "\n";
    for (auto [i, j] : ans) {
        std::cout << i + 1 << " " << j + 1 << "\n";
    }
    
    return 0;
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:58:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |     for (auto [i, j] : ans) {
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 572 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 696 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 7 ms 976 KB Output is correct
13 Correct 7 ms 976 KB Output is correct
14 Correct 7 ms 956 KB Output is correct
15 Correct 7 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 572 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 696 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 7 ms 976 KB Output is correct
13 Correct 7 ms 976 KB Output is correct
14 Correct 7 ms 956 KB Output is correct
15 Correct 7 ms 976 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 6 ms 848 KB Output is correct
19 Correct 6 ms 848 KB Output is correct
20 Correct 6 ms 848 KB Output is correct
21 Correct 6 ms 848 KB Output is correct
22 Correct 6 ms 848 KB Output is correct
23 Correct 6 ms 912 KB Output is correct
24 Correct 6 ms 848 KB Output is correct
25 Correct 6 ms 848 KB Output is correct
26 Incorrect 11 ms 1272 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 6 ms 848 KB Output is correct
6 Correct 6 ms 848 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 6 ms 848 KB Output is correct
9 Correct 6 ms 848 KB Output is correct
10 Correct 6 ms 848 KB Output is correct
11 Correct 6 ms 984 KB Output is correct
12 Correct 6 ms 848 KB Output is correct
13 Correct 6 ms 848 KB Output is correct
14 Correct 6 ms 976 KB Output is correct
15 Correct 8 ms 976 KB Output is correct