Submission #463983

# Submission time Handle Problem Language Result Execution time Memory
463983 2021-08-12T06:31:07 Z tengiz05 Xor Sort (eJOI20_xorsort) C++17
25 / 100
9 ms 1112 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 < 100; i++) {
        int l = rnd() % (n - 1);
        int r = l + 1;
        ans.emplace_back(l, r);
        a[l] ^= a[r];
    }
    
    std::vector<int> bad;
    auto unique = [&]() {
        // return std::set<int>(a.begin(), a.end()).size() == n;
        std::map<int, std::vector<int>> m;
        for (int i = 0; i < n; i++) {
            m[a[i]].push_back(i);
        }
        bad.clear();
        for (auto [x, y] : m) {
            if (y.size() > 1) {
                for (auto t : y) bad.push_back(t);
            }
        }
        return bad.empty();
    };
    
    while (!unique()) {
        int l = rnd() % (n - 1);
        int r = l + 1;
        ans.emplace_back(l, r);
        a[l] ^= a[r];
    }
    
    std::vector<int> b = a;
    std::sort(b.begin(), b.end());
    if (S == 1) {
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j >= 0; j--) {
                if (a[j] != b[j]) {
                    int pos = std::find(a.begin(), a.end(), b[j]) - a.begin();
                    for (; pos < j; pos++) {
                        swap(pos, pos + 1);
                    }
                }
            }
        }
    }
    
    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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 5 ms 720 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 5 ms 732 KB Output is correct
13 Correct 7 ms 804 KB Output is correct
14 Correct 5 ms 732 KB Output is correct
15 Correct 6 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 5 ms 720 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 5 ms 732 KB Output is correct
13 Correct 7 ms 804 KB Output is correct
14 Correct 5 ms 732 KB Output is correct
15 Correct 6 ms 720 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 7 ms 852 KB Output is correct
19 Correct 6 ms 824 KB Output is correct
20 Correct 6 ms 852 KB Output is correct
21 Correct 7 ms 816 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 6 ms 920 KB Output is correct
24 Correct 6 ms 852 KB Output is correct
25 Correct 6 ms 852 KB Output is correct
26 Incorrect 9 ms 1112 KB Integer 46138 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Not sorted
2 Halted 0 ms 0 KB -