제출 #672477

#제출 시각아이디문제언어결과실행 시간메모리
672477CyanmondMalnaRISC (COI21_malnarisc)C++17
0 / 100
1 ms428 KiB
#include <bits/stdc++.h>

int main() {
    int N;
    std::cin >> N;

    std::stack<std::pair<int, int>> swap_stack;
    auto cmpswp = [&](const int a, const int b) {
        if (a < N and b < N) {
            swap_stack.emplace(a, b);
        }
    };

    auto flush = [&]() {
        while (not swap_stack.empty()) {
            const auto [a, b] = swap_stack.top();
            swap_stack.pop();
            std::cout << "CMPSWP" << ' ' << a + 1 << ' ' << b + 1;
            if (swap_stack.empty()) {
                std::cout << std::endl;
            } else {
                std::cout << ' ';
            }
        }
    };

    int M = 1;
    while (M < N) {
        M *= 2;
    }

    for (int len = 2; len <= M; len *= 2) {
        for (int nl = len; nl >= 2; nl /= 2) {
            for (int i = 0; nl * i < M; ++i) {
                const int l = i * nl;
                for (int j = l; j < l + nl / 2; ++j) {
                    if (i % 2 == 0) {
                        cmpswp(j, j + nl / 2);
                    } else {
                        cmpswp(j + nl / 2, j);
                    }
                }
            }
            flush();
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...