#include "registers.h"
#include <vector>
#include <iostream>
constexpr size_t B = 2000;
constexpr int ONE = 50, ALL_ONES = 51, MASK = 52, K_MASK = 53, ALL_ZEROS = 54;
void construct_instructions(int s, int n, int k, int q)
{
std::vector<bool> r(B);
r[0] = 1;
append_store(ONE, r);
fill(r.begin() + 1, r.end(), 1);
append_store(ALL_ONES, r);
fill(r.begin(), r.end(), 0);
for (int i = k; i < B; i += k)
r[i] = 1;
append_store(MASK, r);
fill(r.begin() + k, r.end(), 0);
fill(r.begin(), r.begin() + k, 1);
append_store(K_MASK, r);
fill(r.begin(), r.end(), 0);
append_store(ALL_ZEROS, r);
// writes min in a, max in b
auto append_swap = [&](int a, int b)
{
append_not(40, a);
append_add(40, 40, ONE);
append_add(40, 40, b); // 40 : b - a
append_xor(41, 40, a);
append_xor(41, 41, b); // 41 : (b - a) ^ a ^ b
append_and(40, 41, MASK);
append_right(41, 40, k);
append_not(41, 41);
append_add(41, 41, ONE);
append_add(42, 40, 41); // 42 : 1-mask if a > b, else 0-mask
append_xor(43, a, b);
append_and(43, 43, 42); // 43 : a_i ^ b_i if a_i > b_i
append_xor(a, a, 43); // a_i = min(a_i, b_i)
append_xor(b, b, 43); // b_i = max(a_i, b_I)
};
if (!s)
{
int l = 64;
append_left(2, ALL_ONES, n * k);
append_or(0, 0, 2);
append_move(1, 0);
append_right(0, 0, l * k); // 0 : upper half
append_left(2, ALL_ONES, l * k);
append_or(1, 1, 2); // 1 : lower half
append_print(0);
append_print(1);
while (l)
{
append_swap(0, 1);
l >>= 1;
append_move(1, 0);
append_right(0, 0, l * k);
append_left(2, ALL_ONES, l * k);
append_or(1, 1, 2);
append_print(0);
append_print(1);
}
}
else
{
for (int i = 0; i < n; ++i)
{
if (!(i & 1))
{
append_right(10, 0, i - i / 2);
append_left(11, K_MASK, i / 2);
append_and(10, 10, 11);
append_or(2, 2, 10);
}
else
{
append_right(10, 0, i - i / 2);
append_left(11, K_MASK, i / 2);
append_and(10, 10, 11);
append_or(3, 3, 10);
}
}
append_left(10, ALL_ONES, ((n + 1) / 2) * k);
append_or(2, 2, 10);
append_left(10, ALL_ONES, (n / 2) * k);
append_or(3, 3, 10);
for (int j = 0; j < 2 * n - 3; ++j)
{
append_swap(2, 3);
if (!(j & 1))
{
append_left(3, 3, k);
append_or(3, 3, K_MASK);
}
else
{
append_right(3, 3, k);
}
}
append_move(0, ALL_ZEROS);
for (int i = 0; i < n; ++i)
{
if (!(i & 1))
{
append_left(10, 2, i - i / 2);
append_left(11, K_MASK, i);
append_and(10, 10, 11);
append_or(0, 0, 10);
}
else
{
append_left(10, 3, i - i / 2);
append_left(11, K_MASK, i);
append_and(10, 10, 11);
append_or(0, 0, 10);
}
}
}
}
Compilation message
registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
16 | for (int i = k; i < B; i += k)
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong answer detected in grader |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |