Submission #1114320

# Submission time Handle Problem Language Result Execution time Memory
1114320 2024-11-18T14:14:27 Z siewjh Bit Shift Registers (IOI21_registers) C++17
100 / 100
2 ms 592 KB
#include "registers.h"
#include <bits/stdc++.h>
using namespace std;
const int b = 2000;

void construct_instructions(int s, int n, int k, int q){
	if (s == 0){
		int rnds = 1 + log2(n - 1), tlen = k * (1 << rnds);
		vector<bool> fl(b, 0), kgrp(b, 0);
		for (int i = n * k; i < tlen; i++) fl[i] = 1;
		append_store(10, fl);
		append_or(0, 0, 10);
		for (int i = 0; i < tlen; i += k)
			for (int j = 0; j < k; j++, i++)
				kgrp[i] = 1;
		append_store(11, kgrp);
		for (int i = 0, len = k; i < rnds; i++, len <<= 1){
			append_right(1, 0, len); // 0 has odd pos, 1 has even pos
			append_and(0, 0, 11);
			append_not(2, 1);
			append_and(2, 2, 11); // 2 is negative 1, clean higher pos of 0 and 2
			append_add(3, 0, 2);
			append_right(3, 3, k); // 0 if v0 < v1, 1 if v0 > v1
			append_add(3, 3, 11); // 1...1 and 0...0
			append_and(4, 0, 3);
			append_not(3, 3);
			append_and(5, 1, 3);
			append_or(0, 4, 5); // (v0 & v3) | (v1 & !v3)
		}
	}
	else{
		int tla = (n + 2) * k, tlen = (n + 1) * k;
		vector<bool> fl(b, 0), kgrp(b, 0);
		for (int i = n * k; i < tla; i++) fl[i] = 1;
		append_store(10, fl);
		append_or(0, 0, 10);
		for (int i = 0; i < tlen; i += k)
			for (int j = 0; j < k; j++, i++)
				kgrp[i] = 1;
		append_store(11, kgrp);
		for (int i = 0; i < n; i++){
			if (!(i & 1)){
				append_right(1, 0, k);
				append_and(0, 0, 11);
				append_and(1, 1, 11);
				append_not(2, 1);
				append_and(2, 2, 11);
				append_add(3, 0, 2);
				append_right(3, 3, k);
				append_add(3, 3, 11);
				append_and(4, 0, 3);
				append_and(7, 1, 3);
				append_not(3, 3);
				append_and(5, 1, 3);
				append_and(8, 0, 3);
				append_or(6, 4, 5);
				append_or(9, 7, 8);
				append_left(9, 9, k);
				append_or(0, 6, 9);
			}
			else{
				append_left(1, 0, k);
				append_and(0, 0, 11);
				append_and(1, 1, 11);
				append_not(2, 1);
				append_and(2, 2, 11);
				append_add(3, 0, 2);
				append_right(3, 3, k);
				append_add(3, 3, 11);
				append_and(4, 0, 3);
				append_and(7, 1, 3);
				append_not(3, 3);
				append_and(5, 1, 3);
				append_and(8, 0, 3);
				append_or(6, 4, 5);
				append_or(9, 7, 8);
				append_right(6, 6, k);
				append_or(0, 6, 9);
			}
			append_or(0, 0, 10);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct