#include "registers.h"
using namespace std;
const int m = 100;
const int b = 2000;
const int one_register = 99;
const int temp_mux = 98;
const int minus_one_register = 97;
// puts the opposite of x in t in 2's complement
void opposite(int t, int x){
append_not(t, x);
append_add(t, t, one_register);
}
//compares integers at registers x and y and outputs a whole register, 1 if x <= y, x and y are not written to
void compare(int t, int x, int y){
opposite(t, x);
append_add(t, t, y);
// 1 if x > y
append_right(t, t, b-1);
//puts the output on the whole register and nots it, 1 if x <= y
append_add(t, t, minus_one_register);
}
//mux, uses temp_mux, c should be full of 1's or 0's, x, y, and c are not written to
void mux(int t, int x, int y, int c){
append_and(t, x, c);
append_not(temp_mux, c);
append_and(temp_mux, temp_mux, y);
append_or(t, t, temp_mux);
}
// creates a mask with 1's in between l and r, 0 otherwise
vector<bool> mask1(int l, int r){
vector<bool> res = vector<bool>(b);
for(int i = 0; i < b; i++){
if(l <= i && i < r) res[i] = 1;
}
return res;
}
void extract(int t, int x, int l, int r){
append_store(t, mask1(l, r));
append_and(t, t, x);
}
void min(int t, int x, int y){
compare(t, x, y);
mux(t, x, y, t);
}
void construct_instructions(int s, int n, int k, int q) {
append_store(one_register, mask1(0, 1));
append_store(minus_one_register, mask1(0, b));
append_print(0);
if(s == 0){
const int min_register = 1;
const int extract_register = 2;
// max_value in min_register
append_store(min_register, mask1(0, k));
for(int i = 0; i < n; i++){
int l = i*k;
int r = (i+1)*k;
extract(extract_register, 0, l, r);
append_print(extract_register);
append_print(min_register);
min(min_register, min_register, extract_register);
//append_print(register);
append_left(min_register, min_register, k);
}
append_right(0, min_register, n*k);
}
append_print(0);
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |