# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400476 | galca | MalnaRISC (COI21_malnarisc) | C++14 | 2 ms | 332 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 <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
int n = N;
while (n & (n - 1)) {
n++;
}
vector<int> regs(n);
for (int i=0; i<n; i++) {
regs[i] = i+1;
}
vector<int> stage;
vector<int> r1;
vector<int> r2;
int curr_stage = 0;
for (int k = 2; k <= n; k *= 2) {
for (int j = k / 2; j > 0; j /= 2) {
for (int i = 0; i < n; i++) {
int ip = i ^ j;
if (ip > i) {
int reg1 = regs[i];
int reg2 = regs[ip];
if ((reg1 <= N) && (reg2 <= N)) {
stage.push_back(curr_stage);
r1.push_back(reg1);
r2.push_back(reg2);
//cout << "CMPSWP R" << reg1 << " R" << reg2 << endl;
}
}
}
++curr_stage;
for (int i = 0; i < n; i++) {
regs[i] = i + 1;
}
}
int odd = 0;
for (int i = 0; i < n; i += k) {
if (odd) {
for (int m = 0; m < k / 2; m++) {
regs[i + m] = i + k - m;
regs[i + k - m - 1] = i + m + 1;
}
}
else {
for (int m = 0; m < k / 2; m++) {
regs[i + m] = i + m + 1;
regs[i + k - m - 1] = i + k - m;
}
}
odd ^= 1;
}
}
cout << curr_stage << endl;
curr_stage = 0;
for (int i = 0; i < r1.size(); i++) {
if (stage[i] != curr_stage) {
cout << endl;
}
curr_stage = stage[i];
cout << "CMPSWP R" << r1[i] << " R" << r2[i] << " ";
}
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... |