#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() {
append_and(1, 0, oneNumIndex);
append_right(0, 0, k);
append_and(2, 0, oneNumIndex);
return;
for(int i = 0; i < n; i++) {
append_and(workRegister, 0, oneNumIndex);
if (i != n-1) {
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));
if (n % 2 != 0) {
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_right(workRegister, 0, d);
append_or(0, 0, workRegister);
}
//(a & (a>=b)) ^ (b & (a<b))
void combine() {
append_add(0, negOneIndex, 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;
}
if (k+2 != curr)
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, 2);
append_and(workRegister, workRegister, 1);
//append_xor(1, 1, 2);
append_xor(0, 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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
444 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
444 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |