Submission #463993

# Submission time Handle Problem Language Result Execution time Memory
463993 2021-08-12T06:44:05 Z tengiz05 Xor Sort (eJOI20_xorsort) C++17
0 / 100
6 ms 720 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;
    
    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];
    };
    
    for (int i = 0; i < 1000; i++) {
        int l = rnd() % (n - 1);
        int r = l + 1;
        int type = rnd() % 2;
        if (type) {
            std::swap(l, r);
        }
        a[l] ^= a[r];
        ans.emplace_back(l, r);
    }
    
    std::vector<int> b = a;
    std::sort(b.begin(), b.end());
    if (S == 1) {
        while (!std::is_sorted(a.begin(), a.end())) {
            for (int j = 1; j < n; j++) {
                if (a[j - 1] > a[j]) {
                    int ready = rnd() % 2;
                    if (ready != -1 && (a[j] ^ a[j - 1]) > a[j - 1]) {
                        a[j] ^= a[j - 1];
                        ans.emplace_back(j, j - 1);
                    } else
                        swap(j - 1, j);
                }
            }
        }
    }
    
    std::cout << ans.size() << "\n";
    for (auto [i, j] : ans) {
        std::cout << i + 1 << " " << j + 1 << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 6 ms 720 KB Not sorted
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 6 ms 720 KB Not sorted
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Not sorted
2 Halted 0 ms 0 KB -