luogu#P12093. [NERC2024] BitBitJump

[NERC2024] BitBitJump

题目描述

BitBitJump is a one instruction set computer. Thus, it has only one instruction: bbj a, b, c\texttt{bbj a, b, c}, which copies an aa-th bit of memory to the bb-th bit of memory and then jumps to address cc.

Let's consider a 16-bit BitBitJump computer. It has 2162^{16} bits of memory organized in 2122^{12} 16-bit words. Words are counted from 0, and bits in a word are counted from the least significant (0-th) bit to the most significant (15-th) bit.

This computer has a single instruction pointer register (IP)(\mathrm{IP}), and execution starts with IP=0\mathrm{IP}=0. If the current IP2122\mathrm{IP} \ge 2^{12}-2, the computer stops. Otherwise, it uses the IP\mathrm{IP}-th word as~aa, the (IP+1)(\mathrm{IP}+1)-th word as~bb, the (IP+2)(\mathrm{IP}+2)-th word as cc, and performs the \texttt{bbj a, b, c} instruction: copies the (a&15)(a \& 15)-th bit of the (a4)(a \gg 4)-th word to the (b&15)(b \& 15)-th bit of the (b4)(b \gg 4)-th word, and sets IP=c\mathrm{IP}=c. Here, &\& represents bitwise AND, and \gg represents bitwise shift right operation. Notice that the value of cc is read from memory after the bit copy, so if the instruction modified its own cc, the new value will be used for IP\mathrm{IP}.

For example, the bbj 32, 35, 5\texttt{bbj 32, 35, 5} instruction placed at the memory start will be executed as follows:

  • a=32a=32 and b=35b=35 are read from the memory.
  • The 0-th bit of the 2-nd word (its value is 5&1=15 \& 1 = 1) will be copied to the 3-rd bit of the same word, so the 2-nd word will have the value of 5+23=135 + 2^3 = 13.
  • Then c=13c=13 is read from memory, and IP\mathrm{IP} is set to 13.

Let's call the (2121)(2^{12}-1)-th word (2161621612^{16}-16 \ldots 2^{16}-1-th bits of memory) an IO-word\textit{IO-word}. An x-comparator\textit{x-comparator} is a program which checks whether the value of the IO-word is equal to xx. It should stop after execution of no more than 2122^{12} instructions, leaving the lowest bit of the IO-word equal to 11 if the original value of the IO-word was equal to xx, and 00 otherwise.

Write a program that generates an xx-comparator for the given value of xx.

输入格式

The input contains a single decimal integer xx (0x<2160 \le x < 2^{16}) --- the value for which to build the xx-comparator.

输出格式

The output should contain the xx-comparator program dump. Dump consists of values for the first nn words of the memory (1n21211 \le n \le 2^{12}-1). All other words, except the IO-word, are filled with zeroes.

For each of the nn words, output its value as a four-character hexadecimal number. Values should be delimited by space or new line characters.

0
fff0 0026 0003  fff1 0056 0006  fff2 0086 0009  fff3 00b6 000c  fff4 00e6 000f 
fff5 0116 0012  fff6 0146 0015  fff7 0176 0018  fff8 01a6 001b  fff9 01d6 001e 
fffa 0206 0021  fffb 0236 0024  fffc 0266 0027  fffd 0296 002a  fffe 02c6 002d 
ffff 02f6 0030                                                  
0004 fff0 0fff                                                  
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff 
0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff 
0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff  0000 fff0 0fff 
0000 fff0 0fff

提示

A dump in the sample output contains a 0-comparator. It consists of the following blocks:

  • 16 instructions: the ii-th of them, counting from 0, copies the ii-th bit of the input word to the 6-th bit of its own cc. If the copied bit is zero, it will proceed to the next instruction; otherwise, the next instruction number will be increased by 64.
  • The following instruction copies the 4-th bit of the 0-th word (value 1) to the 0-th bit of the IO-word and jumps to the stop address.
  • 16 unused words filled with 0.
  • 16 equal instructions (starting from word 67). Each of them copies the 0-th bit of the 0-th word (value 0) to the 0-th bit of the IO-word and jumps to the stop address.