Submission #437094

# Submission time Handle Problem Language Result Execution time Memory
437094 2021-06-25T19:02:45 Z Popax21 Bit Shift Registers (IOI21_registers) C++17
58 / 100
2 ms 332 KB
#include <assert.h>
#include "registers.h"

#define NUM_BITS 2000

static inline int ulong(int n) {
	int l = 0;
	while((1 << l) < n) l++;
	return l;
}

void calc_min(int n, int k) {
	//Fill rest of registers with 1s
	{
		std::vector<bool> r(NUM_BITS);
		for(int b = 0; b < NUM_BITS; b++) r[b] = (b >= n*k);
		append_store(1, r);
		append_or(0, 0, 1);
	}

	//Register plane algorithm
	for(int i = 0; i < ulong(n); i++) {
		//Split registers into two planes
		append_move(1, 0);
		append_right(1, 1, (1 << i) * k);

		//Calculate comparsion-add operands
		append_xor(2, 0, 1);
		append_and(3, 2, 0);
		append_and(4, 2, 1);
		append_not(4, 4);

		//Mask operands
		std::vector<bool> m(NUM_BITS);
		for(int b = 0; b < NUM_BITS; b++) m[b] = (((b/k) % (1 << (i+1))) == 0);
		append_store(5, m);
		append_and(3, 3, 5);
		append_and(4, 4, 5);

		//Calculate comparison masks (0 if a is bigger)
		append_add(3, 3, 4);
		append_right(3, 3, k);
		append_and(3, 3, 5);

		append_add(3, 3, 5);
		append_and(3, 3, 5);

		//Update operands
		append_and(0, 0, 3);
		append_not(3, 3);
		append_and(1, 1, 3);
		append_or(0, 0, 1);
	}
}

void sort_array(int n, int k) {
	assert(false);
}

void construct_instructions(int s, int n, int k, int q) {
	if(s == 0) calc_min(n, k);
	else if(s == 1) sort_array(n, k);
	else assert(false);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 224 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 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 -