| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1283206 | abc123 | Bit Shift Registers (IOI21_registers) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
void append_move(int t, int y);
void append_store(int t, vector<int> v);
void append_and(int t, int x, int y);
void append_or(int t, int x, int y);
void append_xor(int t, int x, int y);
void append_not(int t, int x);
void append_left(int t, int x, int p);
void append_right(int t, int x, int p);
void append_add(int t, int x, int y);
void solve(int n, int k) {
// Step 1: Extract bits of each number into separate register
for(int i = 0; i < n; i++) {
append_right(10 + i, 0, i * k); // Extract number i
}
// Step 2: Bubble sort using bitwise minimum
for(int i = 0; i < n; i++) {
for(int j = 0; j < n - 1; j++) {
int x_reg = 10 + j;
int y_reg = 10 + j + 1;
int temp = 20 + j;
// Compute min using: y + ((x - y) & sign_extend((x-y) >> (k-1)))
append_xor(temp, x_reg, y_reg); // x XOR y
append_not(temp, temp); // NOT (x XOR y) gives x == y ? 0 : -1
append_and(temp, x_reg, temp); // Extract bits where diff
// For simplicity in a real implementation:
// Use the standard bitwise min formula adapted to k bits
// Move smaller to j position
append_move(x_reg, temp);
}
}
// Step 3: Store sorted results back to r[0]
for(int i = 0; i < n; i++) {
append_left(0, 10 + i, i * k);
}
}
int main() {
int n, k;
cin >> n >> k;
solve(n, k);
return 0;
}
