#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 {};
}
int m = (a.size() + 1) / 2;
vector<int> lx(a.begin(), a.begin() + m), rx(a.begin() + m, a.end());
vector<int> l, r;
for (int i = 0; i < lx.size(); ++i) {
(i % 2 == 0 ? l : r).push_back(lx[i]);
}
for (int i = 0; i < rx.size(); ++i) {
(i % 2 == 0 ? l : r).push_back(rx[i]);
}
if (a.size() == 2) {
l.clear(), r.clear();
l.push_back(a[0]);
r.push_back(a[1]);
}
auto x = merge(l), y = merge(r);
parallel(x, y);
x.push_back({});
for (int i = a.size() == 2 ? 0 : 1; i + 1 < size(a); ++i) {
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 mid = (l + r + 1) >> 1;
auto x = sort(l, mid), y = sort(mid, r);
parallel(x, y);
vector<int> a(r - l, 0);
iota(a.begin(), a.end(), l);
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
malnarisc.cpp: In function 'void parallel(std::vector<std::vector<std::pair<int, int> > >&, std::vector<std::vector<std::pair<int, int> > >&)':
malnarisc.cpp:10: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]
10 | 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:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < lx.size(); ++i) {
| ~~^~~~~~~~~~~
malnarisc.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < rx.size(); ++i) {
| ~~^~~~~~~~~~~
malnarisc.cpp:36:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = a.size() == 2 ? 0 : 1; i + 1 < size(a); ++i) {
| ~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |