Submission #537899

# Submission time Handle Problem Language Result Execution time Memory
537899 2022-03-15T19:55:04 Z surgutti MalnaRISC (COI21_malnarisc) C++14
100 / 100
1 ms 340 KB
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

vector<pair<int, int>> ans[100];

int merge(int l, int r, int p, int lvl) {
    if (l + 2 * p > r) {
        ans[lvl].emplace_back(l, l + p);
    }
    else {
        
        lvl = max(merge(l + 0, r, p * 2, lvl),
                  merge(l + p, r, p * 2, lvl));
        
        for (int i = l + p; i + p <= r; i += 2 * p)
            ans[lvl].emplace_back(i, i + p);
    }

    return lvl + 1;
}

int sort(int l, int r) {
    if (l == r) return 0;

    int m = (l + r) >> 1;

    int lvl = max(sort(l, m + 0), sort(m + 1, r));

    return merge(l, r, 1, lvl);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    int n; cin >> n;

    int m = 1;
    while (m < n)   m <<= 1;

    int t = sort(0, m - 1);

    cout << t << '\n';

    for (int i = 0; i < t; i++) {
        for (auto [i, j] : ans[i]) if (j < n) {
            cout << "CMPSWP R" << i + 1 << " R" << j + 1 << ' ';
        }
        cout << '\n';
    }
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:48:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         for (auto [i, j] : ans[i]) if (j < n) {
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
# 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct