QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#2402. 堆叠起来

Statistiques

Stacy 最近在 Stacks“R”Us 开始工作,这是一家领先的堆栈相关产品制造商,产品包括儿童积木、煎饼铲和食堂托盘分配器。作为一名新员工,她的任务是测试 Stacks“R”Us 自动化电子堆栈机器系列中的最新产品:Stackulator 3000。

Stackulator 3000 的内存中维护着一个正整数堆栈,并支持三种指令:1d+。前两条指令非常标准:

  • 1:将数字 1 推入堆栈顶部。
  • d:复制堆栈顶部的数字,即将当前栈顶的数字取出并推入两个该数字的副本。在空栈上执行 d 指令是错误的。

不幸的是,由于设计人员与硬件团队之间的沟通不畅,以及对堆栈指针和堆栈条目之间差异的混淆,+ 指令变得有些古怪:

  • +:从堆栈中弹出最上面的两个数字,将所有剩余的堆栈条目减 1,然后将弹出的两个元素相加,并将结果推入堆栈。在包含少于两个整数的堆栈上执行 + 指令是错误的。

例如,执行程序 1d+11+ 会产生图 J.1 所示的堆栈状态序列,最终得到的堆栈包含两个条目,底部为 1,顶部为 2

图 J.1:`1d+11+` 的执行过程

如果在加法运算过程中某个堆栈条目变为 1,它会直接从堆栈中移除,因为堆栈只能容纳正整数。

由于她还是一名学徒堆栈测试员,Stacy 被分配与更有经验的测试员 Stan 一起工作。Stan 建议他们平均分配工作:Stan 负责构思堆栈,而 Stacy 的工作是编写能够生成给定堆栈的 Stackulator 3000 程序。然后他们可以运行 Stacy 的程序,以确保 Stackulator 3000 给出预期的结果。

Stacy 本可以完成这项工作,但她现在忙于寻找另一份工作。这就是你需要介入的地方:请通过创建能够生成 Stan 给定堆栈的 Stackulator 3000 程序来帮助 Stacy。

输入格式

输入的第一行包含一个整数 $1 \le n \le 1000$。接下来的行包含 $n$ 个以空格分隔的正整数,表示从栈底到栈顶的期望堆栈内容。每个整数 $x$ 的范围为 $1 \le x \le 10^6$。

输出格式

输出一行包含一个有效的 Stackulator 3000 程序,该程序在从空栈开始执行时,最终得到的堆栈内容应与期望内容一致。你的程序必须仅由字符 1d+ 组成,且长度不超过 $100\,000$ 个字符。如果存在多个能生成期望堆栈的有效程序,你可以输出其中任意一个。

样例

输入 1

3
1 1 1

输出 1

1dd

输入 2

3
1 2 3

输出 2

11+1+1+1+1+11+1+1+11+1+

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.