QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#4820. Kitten's Computer

Statistics

Kitten 最近计划组装一台属于他自己的计算机。这台计算机拥有 400 个寄存器,每个寄存器可以存储一个 64 位二进制整数,即范围在 $[0, 2^{64} - 1]$ 内的整数。第 $i$ 个($i \in [1, 400]$)寄存器中存储的值记为 $a_i$。该计算机支持 7 种汇编指令:

  • SET i j:令 $a_i := a_j$。
  • XOR i j k:令 $a_i := a_j \oplus a_k$($\oplus$ 为按位异或运算)。
  • AND i j k:令 $a_i := a_j \& a_k$($\&$ 为按位与运算)。
  • OR i j k:令 $a_i := a_j | a_k$($|$ 为按位或运算)。
  • NOT i j:令 $a_i := \sim a_j$($\sim$ 为一元按位取反运算)。
  • LSH i x:将 $a_i$ 左移 $x$ 位。空出的位补 0。
  • RSH i x:将 $a_i$ 右移 $x$ 位。空出的位补 0。

请注意,你需要确保 $1 \le i, j, k \le 400$ 且 $0 \le x < 64$。

你可能认为这台计算机的功能不够强大,但 Kitten 的计算机并非普通的计算机!它拥有一种强大的并行计算方法,可以同时计算所有互不干扰的指令。

形式化地,让我们跟踪 $t_1, t_2, \dots, t_{400}$,它们表示寄存器值被赋值的时间。初始时,所有 $t_i$ 均为 0。每当你执行一条指令时,如果它需要 $a_{j_1}, a_{j_2}, \dots, a_{j_n}$ 作为参数进行计算,并将结果输出到 $a_i$,则令 $t_i = \max\{t_{j_1}, t_{j_2}, \dots, t_{j_n}\} + 1$。程序的运行时间(runtime)定义为所有指令顺序执行过程中产生的 $t_i$ 的最大值。

今天,Kitten 想利用他的计算机设计一个计算器。该计算器用于快速计算 64 位无符号整数的乘法。开始时,寄存器 $a_1$ 和 $a_2$ 分别被设置为两个 64 位无符号整数 $x$ 和 $y$,而其他寄存器被设置为 0。你需要帮助 Kitten 为他的程序设计一系列指令,使得最终 $a_1$ 的值是 $x$ 与 $y$ 的乘积对 $2^{64}$ 取模的结果。

Kitten 要求你的指令总数不超过 100 000 条,且程序的运行时间不超过 70。

输入格式

本题没有输入。

输出格式

输出任意行数(0 到 100 000 行),每行包含一条如上所述格式的指令。

样例

输入 1

<no input>

输出 1

NOT 2 1
RSH 2 63
NOT 3 1
RSH 3 62
NOT 4 1
RSH 4 61
LSH 2 1
LSH 3 9
LSH 4 3
OR 5 2 3
OR 1 5 4

说明

样例输出并不能解决本题,它仅用于演示格式。

当检查你的输出时,校验器将执行以下检查:

  1. 如果你的输出超过 100 000 行,返回 WA 并立即退出。
  2. 如果你的输出包含非法指令,返回 WA 并立即退出。
  3. 执行以下过程 5000 次: (a) 给定两个 64 位无符号整数 $x$ 和 $y$。 (b) 将所有寄存器清零,并令 $a_1 = x$,$a_2 = y$。 (c) 执行你的程序。 (d) 如果运行时间超过 70,返回 WA 并立即退出。 (e) 检查 $a_1$ 的值是否为 $(x \cdot y) \pmod{2^{64}}$。如果不是,返回 WA 并立即退出。
  4. 返回 OK 并立即退出。

注意,校验器只会检查寄存器 $a_1$。其他所有寄存器的最终值可以是任意的。 用于校验的 5000 组 $x$ 和 $y$ 是预先固定的。

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.