Submission #672482

# Submission time Handle Problem Language Result Execution time Memory
672482 2022-12-16T10:26:47 Z Cyanmond MalnaRISC (COI21_malnarisc) C++17
0 / 100
1 ms 212 KB
#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" << ' ' << 'R' << a + 1 << ' ' << 'R' << b + 1;
            if (swap_stack.empty()) {
                std::cout << std::endl;
            } else {
                std::cout << ' ';
            }
        }
    };

    int M = 1;
    while (M < N) {
        M *= 2;
    }
    std::cout << (int)log2(M) * (int)(log2(M + 1) + 1) / 2 << std::endl;

    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 time Memory Grader output
1 Incorrect 0 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB not sorted
2 Halted 0 ms 0 KB -