QOJ.ac

QOJ

مجموع النقاط: 100 إخراج فقط

#4534. New-style Computer

الإحصائيات

This is an answer-submission problem.

The great god of human wisdom, clevertick, spent three weeks building a new type of computer (he only spent three days building the computer itself; the rest of the time was spent compiling and debugging...), which he named CTOX. Now, he can abandon his old machine and use CTOX to complete his work...

CTOX has a sufficiently large (effectively infinite) memory, and its memory addresses are two-dimensional. That is, a memory address can be represented by a pair of integers $(x, y)$. The four addresses adjacent to this address are $(x+1, y)$ (right), $(x, y+1)$ (up), $(x-1, y)$ (left), and $(x, y-1)$ (down). Each memory address can store an integer value in the range $0 \sim 65535$. However, CTOX has no registers, only a single free switch that can be used to store temporary data (since it is a switch, it only has two states: on and off). CTOX can only read or write one memory address at a time. It uses a pointer to indicate the memory address currently being read or written. Moving the read/write pointer from one address to an adjacent address is called moving one unit. Every time CTOX starts, it initializes: it clears all memory (sets all stored values to $0$), turns off the free switch, and points the read/write pointer to $(0, 0)$.

Due to the special architecture of CTOX, when programming it, one must use a special instruction set (also designed by clevertick). The instructions included in this set are:

x: If the switch is on, the pointer moves $1$ unit to the left; otherwise, it moves $1$ unit to the right.

X: If the switch is on, the pointer moves to the left; otherwise, it moves to the right. The number of units moved is equal to the value stored at the memory address the pointer was pointing to before the move.

u: If the switch is on, the pointer moves $1$ unit up; otherwise, it does nothing.

U: If the switch is on, the pointer moves up by a number of units equal to the value stored at the memory address the pointer was pointing to before the move; otherwise (if the switch is off), it does nothing.

d: If the switch is on, the pointer moves $1$ unit down; otherwise, it does nothing.

D: If the switch is on, the pointer moves down by a number of units equal to the value stored at the memory address the pointer was pointing to before the move; otherwise (if the switch is off), it does nothing.

I: If the switch is on, the value stored at the memory address the pointer is pointing to is incremented by $1$ (if the original value is $65535$, it becomes $0$ after incrementing); otherwise (if the switch is off), it does nothing.

S: If the value stored at the memory address the pointer is currently pointing to is odd, turn the switch on; otherwise, turn the switch off.

P: Toggle the switch (if it was on, turn it off; if it was off, turn it on).

l: Left-shift the value stored at the memory address the pointer is currently pointing to by $1$ bit (first convert to a $16$-bit binary number, then discard the most significant bit, shift the remaining bits left by $1$ position, and fill the least significant bit with $0$).

r: Right-shift the value stored at the memory address the pointer is currently pointing to by $1$ bit (first convert to a $16$-bit binary number, then discard the least significant bit, shift the remaining bits right by $1$ position, and fill the most significant bit with $0$).

v: Reverse the bits of the value stored at the memory address the pointer is currently pointing to (first convert to a $16$-bit binary number, then reverse it, i.e., $x_{15}x_{14} \cdots x_{1}x_{0}$ becomes $x_{0}x_{1} \cdots x_{14}x_{15}$).

E: Terminates the execution of the entire program. Once this instruction is executed, the program terminates immediately. This is the only instruction that can terminate the program.

In addition, it contains two special bracket formats:

(instruction sequence)number: Executes the instruction sequence inside the brackets a specified number of times. The number must be present and must be a constant with a value of $1 \sim 65535$. For example, (u)3 means that if the switch is on, the pointer moves $3$ units up; otherwise, it does nothing.

[instruction sequence]: While the switch is on, repeatedly execute the instruction sequence inside the brackets, equivalent to while(switch is on){instruction sequence}.

When a CTOX program executes, all instruction sequences without brackets are executed strictly from left to right. The program terminates if and only if the E instruction is executed (if the end of the program is reached without encountering an E instruction, an error will occur). The space in memory used to store the program is located very far from $(0, 0)$ (you can consider it infinitely far, meaning the execution of the program will not corrupt the program itself), but this space is not large enough, so your program can contain at most $10000$ characters (brackets and numbers are also counted as characters). Furthermore, if a program has executed $20120526$ instructions and has not yet terminated, the CTOX processor will consider the program dead and forcibly terminate it.

clevertick finished his work quickly using CTOX. Suddenly, someone with a lower IQ discovered the power of CTOX and wanted to use it as well. clevertick obviously would not agree directly, so he assigned this person $10$ tasks, requiring him to program using the CTOX instruction set to complete these $10$ tasks. Since this person has a low IQ and cannot complete the tasks, he is asking for your help. Can you help him?

These $10$ tasks correspond to the $10$ test cases of this problem, and the task number is the test case number. (Note: For each task, initially, except for the memory addresses specified in the task description, all other memory addresses store $0$, the switch is off, and the pointer is at $(0, 0)$.)

  1. Initially, address $(0, 0)$ stores a value. If the value is even, the pointer must terminate at $(1, 1)$. Otherwise (if it is odd), the pointer must terminate at $(-1, -1)$. Upon termination, there are no restrictions on the values stored at any address or the state of the switch.
  2. Initially, address $(0, 0)$ stores a value. If the value is a multiple of $4$, the pointer must stop at $(1, 1)$. Otherwise (if it is not a multiple of $4$), the pointer must terminate at $(-1, -1)$. Upon termination, there are no restrictions on the values stored at any address or the state of the switch.
  3. Initially, address $(0, 0)$ stores a value. You are required to assign this value to address $(2, 3)$. Upon termination, except for the value at address $(2, 3)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.
  4. Initially, addresses $(1, 1)$ and $(-1, -1)$ each store a value. You are required to determine if these two values are equal. If they are equal, store $1$ at address $(0, 0)$; if they are not equal, store $2$ at address $(0, 0)$. Upon termination, except for the value at address $(0, 0)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.
  5. Initially, addresses $(1, 1)$ and $(-1, -1)$ each store a value. Calculate the bitwise AND of these two values and store the result at address $(0, 0)$. Upon termination, except for the value at address $(0, 0)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.
  6. Initially, addresses $(1, 1)$ and $(-1, -1)$ each store a value. Calculate the bitwise XOR of these two values and store the result at address $(0, 0)$. Upon termination, except for the value at address $(0, 0)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.
  7. Initially, addresses $(1, 1)$ and $(-1, -1)$ each store a value. Calculate the sum of these two values modulo $65536$ and store the result at address $(0, 0)$. Upon termination, except for the value at address $(0, 0)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.
  8. Initially, $64$ numbers are stored sequentially at addresses $(1, 0), (2, 0) \cdots (64, 0)$, among which there is exactly one $0$. You are required to find the address where this value is $0$ and terminate there. Upon termination, there are no restrictions on the values stored at any address or the state of the switch.
  9. Initially, $32768$ numbers are stored sequentially at addresses $(1, 0), (2, 0) \cdots (32768, 0)$, among which there is exactly one $0$. You are required to find the position where this value is $0$ and terminate there. Upon termination, there are no restrictions on the values stored at any address or the state of the switch.
  10. Initially, $4096$ numbers are stored sequentially at addresses $(1, 0), (2, 0) \cdots (4096, 0)$. Find the maximum value among these and store it at address $(0, 0)$. Upon termination, except for the value at address $(0, 0)$, there are no restrictions on the values at other addresses, the pointer position, or the switch state.

There is no input file for this problem. You need to submit the corresponding output files ctox1.out ~ ctox10.out for these $10$ tasks. Each output file should contain one line, which is the program you wrote (if the output file has multiple lines, all lines except the first one will be discarded during evaluation).

How to Test Your Program

This problem provides a testing tool—the simulator simulator (Linux) / simulator.exe (Windows). You can use it in the following two ways:

Method 1: ./simulator <program file> (Linux) / simulator.exe <program file> (Windows)

The simulator will read the first line of the program file as the program, execute it, and write the result at the time of termination to log.txt. In this mode, all memory addresses are initially $0$.

Method 2: ./simulator <program file> <input file> (Linux) / simulator.exe <program file> <input file> (Windows)

The input file contains three integers $x, y, v$ per line, indicating that the initial value at memory address $(x, y)$ is set to $v$. It must satisfy $0 \leq v \leq 65535$; if it does not, it is treated as an end-of-file marker (all subsequent content will be discarded).

The simulator will read each line of the input file until it encounters a line that does not satisfy $0 \leq v \leq 65535$, set the initial values for the corresponding memory addresses, then read the first line of the program file as the program, execute it, and write the result at the time of termination to log.txt. In this mode, except for the addresses specified in the input file, all memory addresses are initially $0$.

log.txt contains the number of steps the program executed (one step per instruction), as well as the state of CTOX when the program terminated—pointer position, switch state, and all memory addresses with non-zero values and their stored values.

If the corresponding file does not exist, the program has a syntax error (contains illegal characters, mismatched brackets, numbers after () not in the range $1 \sim 65535$, etc.), the length exceeds $10000$ characters, the number of execution steps exceeds $20120526$, or the E instruction is not found when the end of the program is reached, the simulator will report an error, and no log.txt file will be generated.

Subtasks

During evaluation, we set $10$ sets of data for each test case. Each set of data represents an initial configuration for that test case (i.e., the values stored at the addresses that have initial values). The data scale is set with a certain gradient.

For each test case:

If you do not submit the corresponding output file, the program in the submitted output file has a syntax error, or the character count of the program exceeds $10000$, you will receive $0$ points for all data in that test case.

Otherwise, we will execute your submitted program using each set of data for that test case as input. For that set of data, if your program does not complete the task requirements or the number of execution steps exceeds $20120526$, you will receive $0$ points; otherwise, you will receive $1$ point.

Your score for this problem is the sum of the scores for all data in all test cases.

Note

Please keep all additional files safe to avoid accidental deletion or modification.


أو قم برفع الملفات واحداً تلو الآخر:

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.