Submission #640551

# Submission time Handle Problem Language Result Execution time Memory
640551 2022-09-14T21:11:58 Z Aderfish Bit Shift Registers (IOI21_registers) C++17
0 / 100
1 ms 340 KB
#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;
const int temp_min = 96;

const int bal_odd_mask = 95;
const int unbal_mask = 94;
const int rep_one_mask = 93;
const int ball_even_mask = 92;

// 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);
}

// i is start intdex, w is width
void extract_shift(int t, int x, int i, int w){
	append_left(t, x, b-w-i);
	append_right(t, t, b-w);
}

void min(int t, int x, int y){
	compare(temp_min, x, y);
	mux(t, x, y, temp_min);
}

vector<bool> even_balanced_mask(int w){
	vector<bool> r(b);
	for(int i = 0; i < b; i++){
		if((i/w)%2 == 0) r[i] = true;
		else r[i] = false;
	}

	return r;
}

vector<bool> odd_balanced_mask(int w){
	vector<bool> r(b);
	for(int i = 0; i < b; i++){
		if((i/w)%2 == 1) r[i] = true;
		else r[i] = false;
	}

	return r;
}

vector<bool> even_unbalanced_mask(int w){
	vector<bool> r(b);
	
	for(int i = 0; i < b; i++){
		int m = i%(2*w);
		if(m < w+1) r[i] = true;
		else r[i] = false;
	}

	return r;
}

vector<bool> repeated_one(int w){
	vector<bool> r(b);
	
	for(int i = 0; i < b; i++){
		int m = i%(2*w);
		if(m == 0) r[i] = true;
		else r[i] = false;
	}

	return r;
}

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));

	if(s == 0){
		if(k == 1){
			append_add(0, 0, one_register);
			append_right(0, 0, n);
		}

		const int even = 1;
		const int odd = 2;
		const int opposite_and_cond = 3;

		int w = k;
		while(w < n*k){
			append_print(0);

			append_store(ball_even_mask, even_balanced_mask(w));
			append_store(bal_odd_mask, odd_balanced_mask(w));
			append_store(unbal_mask, even_unbalanced_mask(w));
			append_store(rep_one_mask, repeated_one(w));

			// extraction
			append_and(even, ball_even_mask, 0);
			append_and(odd, bal_odd_mask, 0);
			append_right(odd, odd, w);

			// taking the opposite of the extracted nums
			append_xor(opposite_and_cond, odd, unbal_mask);
			append_add(opposite_and_cond, odd, rep_one_mask);

			// adding the 2 halves
			append_add(opposite_and_cond, even, odd);

			// extracting the most sign bit
			append_right(opposite_and_cond, opposite_and_cond, w);
			append_and(opposite_and_cond, opposite_and_cond, ball_even_mask);
			append_add(opposite_and_cond, opposite_and_cond, ball_even_mask);

			// should not be necessary
			// append_and(opposite_and_cond, opposite_and_cond, ball_even_mask);
			// 1's means odd <= even
			
			mux(0, odd, even, opposite_and_cond);

			w <<= 1;
		}


	}

	append_print(0);

	return;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Incorrect min value
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 1 ms 212 KB Incorrect min value
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Incorrect min value
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 -