QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 2048 MB Puntuación total: 100

#10463. 加法还是乘法

Estadísticas

工业计算机处理器公司提供非常快速、专门定制的处理器以满足客户需求。$a$-$C$-$m$ 系列处理器(例如 $1$-$C$-$2$ 和 $5$-$C$-$3$)的指令集仅包含两种不同的操作:

A:加 $a$ M:乘 $m$

处理器接收一个整数,执行一系列 A 和 M 操作(程序)来修改输入,并输出结果。例如,$1$-$C$-$2$ 处理器执行程序 AAAM,输入为 $2$ 时,输出为 $10$(计算过程为 $2 \to 3 \to 4 \to 5 \to 10$);而 $5$-$C$-$3$ 处理器在相同的程序和输入下输出 $51$($2 \to 7 \to 12 \to 17 \to 51$)。

你是一名被分配到绝密项目的 $a$-$C$-$m$ 程序员。这意味着你并未被告知程序需要执行的具体计算。但你已知特定的数值 $p, q, r$ 和 $s$,并满足以下条件:

  1. 输入保证在 $p$ 和 $q$ 之间。
  2. 输出必须在 $r$ 和 $s$ 之间。

给定一个 $a$-$C$-$m$ 处理器以及数值 $p, q, r$ 和 $s$,你的任务是构造一个最短的 $a$-$C$-$m$ 程序,使得对于所有满足 $p \le x \le q$ 的输入 $x$,其输出 $y$ 均满足 $r \le y \le s$。如果存在多个长度相同的最短程序,请选择字典序最小的一个,将程序视为由 A 和 M 组成的字符串。

输入格式

输入包含多个测试用例。每个测试用例由一行包含的六个整数 $a, m, p, q, r$ 和 $s$ 给出,如上所述($1 \le a, m, p, q, r, s \le 10^9, p \le q$ 且 $r \le s$)。

最后一个测试用例后跟一行六个零。

输出格式

对于每个测试用例,显示其用例编号,后跟上述的最优程序。如果最优程序不包含任何操作,则显示单词 “empty”。如果不存在满足规范的程序,则显示单词 “impossible”。

将程序显示为一系列以空格分隔的字符串,交替出现 “$n$A” 形式的字符串和 “$n$M” 形式的字符串,其中 $n > 0$。前一种类型的字符串表示 $n$ 次连续的 A 操作,后一种类型的字符串表示 $n$ 次连续的 M 操作。

请遵循样例输出的格式。

样例

样例输入 1

1 2 2 3 10 20
1 3 2 3 22 33
3 2 2 3 4 5
5 3 2 3 2 3
0 0 0 0 0 0

样例输出 1

Case 1: 1A 2M
Case 2: 1M 2A 1M
Case 3: impossible
Case 4: empty

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.