QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9279. 矩阵 4

Statistics

Matrix 4 即将上映!有传言称,这部史诗电影的主要情节转折之一是 Neo 在一个 4 维迷宫中寻找 Trinity。

迷宫中的每个点都可以看作一个 $2 \times 2$ 的矩阵。Neo 最初位于矩阵 $S = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}$。Trinity 被囚禁在矩阵 $F = \begin{pmatrix} p & q \\ r & s \end{pmatrix}$ 中。

从迷宫中的每个矩阵出发,你可以向 4 个方向之一移动,分别用字母 $a, A, b, B$ 表示。当从矩阵 $X$ 采取方向 $c \in \{a, A, b, B\}$ 时,你将到达矩阵 $XM_c$($X$ 与 $M_c$ 的矩阵乘积),其中 $M_c$ 定义如下:

$$M_a = \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix}, \quad M_A = \begin{pmatrix} 1 & -2 \\ 0 & 1 \end{pmatrix}, \quad M_b = \begin{pmatrix} 1 & 0 \\ 2 & 1 \end{pmatrix}, \quad M_B = \begin{pmatrix} 1 & 0 \\ -2 & 1 \end{pmatrix}$$

你的任务是帮助 Neo 从 $S$ 到达 $F$,或者判断这是不可能的。如果可能,你还需要为 Neo 提供到达 $F$ 的路径描述。路径应表示为一系列步骤;步骤可以是重复组,看起来像是一系列步骤重复任意正整数次;重复组可能包含其他重复组。

形式上,路径由以下文法定义: <route> := <empty> | <step><route>; <step> := a | A | b | B | (<route>)<count>; 其中 <empty> 是空字符串,<count> 是正整数。

遵循路径意味着从左到右执行路径中的每一步。遵循步骤意味着执行相应的方向或将内部路径执行 <count> 次。

输入格式

第一行包含 $T$ ($1 \le T \le 10\,000$),即测试用例的数量。 接下来的 $T$ 行,每行包含四个整数 $p, q, r, s$ ($-1\,000\,000 \le p, q, r, s \le 1\,000\,000$),定义了 Trinity 被囚禁的矩阵 $F = \begin{pmatrix} p & q \\ r & s \end{pmatrix}$ 的分量。

输出格式

对于每个测试用例,打印单词 “Impossible” 或打印一条从 $S$ 到 $F$ 的路径。不要打印任何多余的空格,严格遵守上述形式文法。允许空路径。

任何重复组步骤中的重复次数不应超过 $10^9$。 路径长度不应超过 1 KiB (1024 字节),即路径描述行的长度不应超过 1024。

检查程序将使用快速矩阵幂运算来评估你的路径。如果在任何时刻,任何中间矩阵的元素绝对值大于 $10^9$,你将获得该测试的 Wrong Answer 判决。

样例

输入 1

3
-7 4 -2 1
25 12 -48 -23
-1 0 0 1

输出 1

aaB
(B(a)3b)2
Impossible

说明

在第一个样例中,路径带领 Neo 经过以下矩阵序列:

$$\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \to \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix} \to \begin{pmatrix} 1 & 4 \\ 0 & 1 \end{pmatrix} \to \begin{pmatrix} -7 & 4 \\ -2 & 1 \end{pmatrix}$$

第二个样例中的路径等价于以下路径:BaaabBaaab

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.