#include <iostream>
#include <vector>
#include <utility>
using namespace std;
vector<pair<int, int>> ans[100];
int merge(int l, int n, int r, int lvl) {
if (2 * r >= n) {
ans[lvl].emplace_back(l, l + r);
}
else {
lvl = max(merge(l, n, 2 * r, lvl),
merge(l + r, n, 2 * r, lvl));
for (int i = l + r; i + r < l + n; i += 2 * r)
ans[lvl].emplace_back(i, i + r);
}
return lvl + 1;
}
int sort(int l, int n) {
return n > 1 ? merge(l, n, 1, max(sort(l, n / 2), sort(l + n / 2, n / 2))) : 0;
}
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);
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:41:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
41 | for (auto [i, j] : ans[i]) if (j < n) {
| ^
# |
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 |
1 ms |
328 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 |
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 |