#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#include "registers.h"
int s, n, k, q;
int ops = 0;
vector<bool> negOne(2000);
vector<bool> signBit(2000);
vector<bool> oneNum(2000);
const int negOneIndex = 99;
const int signBitIndex = 98;
const int oneNumIndex = 97;
const int workRegister = 96;
void spread() {
for(int i = 0; i < n; i++) {
append_and(workRegister, 0, oneNumIndex);
append_left(oneNumIndex, oneNumIndex, k+2);
append_left(0, 0, 2);
append_or(1, 1, workRegister);
}
}
void divide() {
int leftNumbers = (n+1) / 2;
append_move(2, 1);
append_right(2, 2, leftNumbers * (k+2));
vector<bool> tempExtra(2000);
rep(i,0,2000) {
tempExtra[i] = (n-leftNumbers)*(k+2) <= i && i < (n-leftNumbers+1)*(k+2)-1;
}
append_store(3, tempExtra);
append_or(2, 2, 3);
}
void spreadSigns(int d) {
append_move(workRegister, 0);
append_right(workRegister, workRegister, d);
append_or(0, 0, workRegister);
}
void combine() {
append_store(0, negOne);
append_add(0, 0, 2); // b-1
append_not(0, 0); // !(b-1)
append_add(0, 0, 1); // a-b
append_and(0, 0, signBitIndex);
rep(_,0,k+1) spreadSigns(1);
//int curr = 1;
//while(curr*2 < k+2) {
// spreadSigns(curr);
// curr *= 2;
//}
//spreadSigns(k+2 - curr);
append_not(workRegister, 0);
// registry 0 contains zeros if a >= b, else 1
// => registry 0 contains a >= b
// => workRegister contains a < b
append_and(0, 0, 1);
append_and(workRegister, workRegister, 2);
append_xor(1, 1, 2);
append_xor(2, 0, workRegister);
append_xor(1, 1, 2);
}
void print() {
rep(i,0,3) append_print(i);
}
void findMin() {
spread();
while(n > 1) {
print();
divide();
print();
combine();
print();
n = (n+1) / 2;
}
print();
append_move(0, 1);
}
void construct_instructions(int _s, int _n, int _k, int _q) {
s = _s;
n = _n;
k = _k;
q = _q;
int a = 0;
int b = k+2;
while(b < 2000) {
for(int j = a; j < b; j++) negOne[j] = j != b-1;
a = b;
b += k+2;
}
for(int i = 0; i < 2000; i++) {
signBit[i] = i % (k+2) == k+1;
oneNum[i] = i < k;
}
append_store(negOneIndex, negOne);
append_store(signBitIndex, signBit);
append_store(oneNumIndex, oneNum);
if (s == 0) {
findMin();
}
else {
assert(false);
}
assert(ops <= q);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer detected in grader |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer detected in grader |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |