# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
997946 | piOOE | MalnaRISC (COI21_malnarisc) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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 {};
}
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);
for (int t = 0; t < 2; ++t) {
x.push_back({});
for (int i = 0; i + 1 < a.size(); i += 2) {
x.back().push_back({a[i], a[i + 1]});
}
}
return x;
}
vector<vector<pair<int, int>>> sort(int l, int r) {
if (l + 1 == r) {
return {};
}
int mid = l + r >> 1;
auto x = sort(l, mid), y = sort(mid, r);
parallel(x, y);
vector<int> a(r - l, l);
iota(a.begin(), a.end(), 0);
auto z = merge(a);
x.insert(x.end(), z.begin(), z.end());
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |