Submission #527796

# Submission time Handle Problem Language Result Execution time Memory
527796 2022-02-18T10:03:57 Z KoD MalnaRISC (COI21_malnarisc) C++17
100 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<std::string> ans;
    vector<pair<int, int>> query;
    const auto flush = [&] {
        std::stringstream s;
        bool f = true;
        for (const auto& [i, j] : query) {
            if (f) {
                f = false;
            } else {
                s << ' ';
            }
            s << "CMPSWP R" << std::to_string(i + 1) << " R" << std::to_string(j + 1);
        }
        ans.push_back(s.str());
        query.clear();
    };
    for (int len = 1; len < N; len *= 2) {
        for (int i = 0; i < N; i += len * 2) {
            for (int j = 0; j < len; ++j) {
                const int l = i + j;
                const int r = i + 2 * len - j - 1;
                if (r < N) {
                    query.emplace_back(l, r);
                }
            }
        }
        flush();
        for (int w = len; w > 1; w /= 2) {
            for (int i = 0; i < N; i += w) {
                for (int j = 0; j < w / 2; ++j) {
                    const int l = i + j;
                    const int r = i + j + w / 2;
                    if (r < N) {
                        query.emplace_back(l, r);
                    }
                }
            }
            flush();
        }
    }
    std::cout << ans.size() << '\n';
    for (const auto& s : ans) {
        std::cout << s << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct