Submission #672489

# Submission time Handle Problem Language Result Execution time Memory
672489 2022-12-16T10:32:20 Z Cyanmond MalnaRISC (COI21_malnarisc) C++17
40 / 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 (j / len % 2 == 0) {
                        cmpswp(j, j + nl / 2);
                    } else {
                        cmpswp(j + nl / 2, j);
                    }
                }
            }
            flush();
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# 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 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
# 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 -