Submission #998012

# Submission time Handle Problem Language Result Execution time Memory
998012 2024-06-13T07:58:31 Z piOOE MalnaRISC (COI21_malnarisc) C++17
100 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;

void parallel(vector<vector<pair<int, int>>> &x, vector<vector<pair<int, int>>> &y) {
    if (x.size() < y.size()) {
        x.resize(y.size());
    }
    for (int i = 0; i < y.size(); ++i) {
        x[i].insert(x[i].end(), y[i].begin(), y[i].end());
    }
}

vector<vector<pair<int, int>>> merge(vector<int> a) {
    if (a.size() == 1) {
        return {};
    }
    assert((a.size() & (a.size() - 1)) == 0);
    vector<int> l, r;
    for (int x : a) {
        (l.size() <= r.size() ? l : r).push_back(x);
    }
    auto x = merge(l), y = merge(r);
    parallel(x, y);
    x.push_back({});
    for (int i = a.size() > 2; i + 1 < a.size(); i += 2) {
        if (a[i] < n && a[i + 1] < n) {
            x.back().push_back({a[i], a[i + 1]});
        }
    }
    if (x.back().empty()) {
        x.pop_back();
    }
    return x;
}

vector<vector<pair<int, int>>> sort(int l, int r) {
    if (l + 1 == r) {
        return {};
    }
    int s = 1 << __lg(r - l - 1);
    auto x = sort(l, l + s), y = sort(l + s, r);
    parallel(x, y);
    vector<int> a(2 * s, 0);
    iota(a.begin(), a.end(), l);
    fill(a.begin() + r - l, a.end(), n);
    auto z = merge(a);
    x.insert(x.end(), z.begin(), z.end());
    return x;
}

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

    cin >> n;

    auto res = sort(0, n);
    cout << res.size() << '\n';
    for (auto &t : res) {
        for (auto [i, j] : t) {
            cout << "CMPSWP " << "R" << i + 1 << " " << "R" << j + 1 << " ";
        }
        cout << '\n';
    }

    return 0;
}

Compilation message

malnarisc.cpp: In function 'void parallel(std::vector<std::vector<std::pair<int, int> > >&, std::vector<std::vector<std::pair<int, int> > >&)':
malnarisc.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < y.size(); ++i) {
      |                     ~~^~~~~~~~~~
malnarisc.cpp: In function 'std::vector<std::vector<std::pair<int, int> > > merge(std::vector<int>)':
malnarisc.cpp:29:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = a.size() > 2; i + 1 < a.size(); i += 2) {
      |                                ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct