제출 #463987

#제출 시각아이디문제언어결과실행 시간메모리
463987tengiz05Xor Sort (eJOI20_xorsort)C++17
25 / 100
8 ms972 KiB
#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 < 600; 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> bad;
    auto unique = [&]() {
        return std::set<int>(a.begin(), a.end()).size() == n;
    };
    
    // while (!unique()) {
    //     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) {
        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;
}

컴파일 시 표준 에러 (stderr) 메시지

xorsort.cpp: In lambda function:
xorsort.cpp:41:57: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |         return std::set<int>(a.begin(), a.end()).size() == n;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:40:10: warning: variable 'unique' set but not used [-Wunused-but-set-variable]
   40 |     auto unique = [&]() {
      |          ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...