Submission #591530

# Submission time Handle Problem Language Result Execution time Memory
591530 2022-07-07T14:39:29 Z rainboy Bit Shift Registers (IOI21_registers) C++17
100 / 100
7 ms 1176 KB
#include "registers.h"
#include <vector>

using namespace std;

typedef vector<bool> vb;

int N = 128, L = 7;
const int B = 2000;

void construct_instructions(int s, int n, int k, int q) {
	vb tmp(B, 0);
	int h, u, v, l, l_;

	if (s == 0) {
		if (n <= 2)
			N = 2, L = 1;
		for (h = 0; h < B; h++)
			tmp[h] = h / k >= n;
		append_store(25, tmp), append_or(0, 0, 25);
		for (h = 0; h < B; h++)
			tmp[h] = 0;
		for (l = 0; l < L; l++) {
			for (u = 0; u < N; u++)
				for (h = 0; h < k; h++)
					tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0;
			append_store(25, tmp);
			append_right(2, 0, k << l), append_and(1, 0, 25), append_and(2, 2, 25), append_xor(3, 1, 2);
			append_not(1, 1), append_add(4, 1, 2), append_not(1, 1);
			for (u = 0; u < N; u++)
				for (h = 0; h < k; h++)
					tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0 && h == 0;
			append_store(25, tmp), append_right(4, 4, k), append_and(4, 4, 25);
			for (u = 0; u < N; u++)
				for (h = 0; h < k; h++)
					tmp[u * k + h] = (u == 0 || (u - 1 & (1 << l + 1) - 1) == 0) && h == 0;
			append_store(25, tmp), append_not(4, 4), append_add(4, 25, 4);
			append_and(3, 3, 4);
			append_left(4, 3, k << l), append_or(3, 3, 4);
			append_xor(0, 0, 3);
		}
	} else {
		if (n == 2)
			N = n, L = 1;
		for (l = 0; l < L; l++) {
			if (l > 0)
				for (u = 0; u < N; u++) {
					if ((u & 1 << l) != 0 && (u & 1 << l - 1) == 0) {
						v = u ^ (1 << l) - 1;
						for (h = 0; h < B; h++)
							tmp[h] = h / k == u;
						append_store(29, tmp);
						append_right(1, 0, (v - u) * k), append_xor(1, 0, 1);
						append_and(1, 1, 29);
						append_left(2, 1, (v - u) * k);
						append_or(1, 1, 2);
						append_xor(0, 0, 1);
					}
				}
			for (l_ = l; l_ >= 0; l_--) {
				append_right(1, 0, k << l_);
				append_xor(2, 0, 1);
				append_not(1, 1), append_and(3, 0, 1), append_or(4, 0, 1), append_not(1, 1);
				append_move(5, 99);
				for (h = 0; h < k; h++) {
					append_or(5, 5, 3), append_and(5, 5, 4);
					if (h + 1 < k)
						append_left(5, 5, 1);
					else
						append_right(5, 5, k - 1);
				}
				for (u = 0; u < N; u++)
					for (h = 0; h < k; h++)
						tmp[u * k + h] = (u & 1 << l_) == 0 && h == 0;
				append_store(29, tmp), append_and(5, 5, 29);
				for (h = 0; h + 1 < k; h++)
					append_left(6, 5, 1), append_or(5, 5, 6);
				for (u = 0; u < N; u++)
					for (h = 0; h < k; h++)
						tmp[u * k + h] = (u & 1 << l_) == 0;
				append_and(5, 5, 2);
				append_store(29, tmp), append_and(5, 5, 29);
				append_left(6, 5, k << l_), append_or(5, 5, 6);
				append_xor(0, 0, 5);
			}
		}
		append_right(0, 0, (N - n) * k);
	}
}

Compilation message

registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:26:36: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   26 |      tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0;
      |                                  ~~^~~
registers.cpp:26:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   26 |      tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0;
      |                            ~~~~~~~~~~~~~^~~
registers.cpp:32:36: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   32 |      tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0 && h == 0;
      |                                  ~~^~~
registers.cpp:32:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   32 |      tmp[u * k + h] = (u & (1 << l + 1) - 1) == 0 && h == 0;
      |                            ~~~~~~~~~~~~~^~~
registers.cpp:36:51: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   36 |      tmp[u * k + h] = (u == 0 || (u - 1 & (1 << l + 1) - 1) == 0) && h == 0;
      |                                                 ~~^~~
registers.cpp:36:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   36 |      tmp[u * k + h] = (u == 0 || (u - 1 & (1 << l + 1) - 1) == 0) && h == 0;
      |                                   ~~^~~
registers.cpp:48:43: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   48 |      if ((u & 1 << l) != 0 && (u & 1 << l - 1) == 0) {
      |                                         ~~^~~
registers.cpp:49:24: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   49 |       v = u ^ (1 << l) - 1;
      |               ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1176 KB Output is correct
2 Correct 6 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1176 KB Output is correct
2 Correct 6 ms 1068 KB Output is correct
3 Correct 6 ms 1064 KB Output is correct
4 Correct 7 ms 1076 KB Output is correct
5 Correct 6 ms 1140 KB Output is correct
6 Correct 6 ms 1144 KB Output is correct
7 Correct 6 ms 1064 KB Output is correct