QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 512 MB 총점: 100 해킹 가능 ✓

#16722. 经济打印

통계

Helen 有一份包含 $10^9$ 页的超长文档,页码从 $1$ 到 $10^9$ 编号。她收到了一份需要打印的页码列表 $p_1, p_2, \dots, p_n$。Helen 热爱大自然,非常关心树木保护,因此她希望对列表中的每一页都恰好打印一份,且不打印任何其他页。为了实现这一目标,她可以使用以下四种类型的标记(token)来构建打印指令:

  • 单个索引 “$i$”:该标记表示打印页码 $i$。
  • 区间 “$i_1-i_2$”:该标记表示打印从 $i_1$ 到 $i_2$(含边界)的所有页面。
  • 偶数区间 “$i_1\%i_2$”:此处 $i_1$ 和 $i_2$ 必须均为偶数。该标记表示打印从 $i_1$ 到 $i_2$(含边界)的所有偶数页。
  • 奇数区间 “$i_1\#i_2$”:此处 $i_1$ 和 $i_2$ 必须均为奇数。该标记表示打印从 $i_1$ 到 $i_2$(含边界)的所有奇数页。

打印指令由任意数量、任意类型的标记组成,标记之间用逗号隔开。请注意,只要某个页面与任意一个标记匹配,它就会被打印。但 Helen 要求列表中的每个页面都只能被打印一次,且不希望打印任何不在列表中的页面。同时,为了节省屏幕空间,她希望你找到一条长度最短的正确打印指令。指令的长度等于写下该指令所使用的总字符数

输入格式

输入的第一行包含一个整数 $n$($1 \le n \le 200\,000$),表示 Helen 想要打印的页面数量。

第二行包含 $n$ 个互不相同的整数 $p_i$($1 \le p_i \le 10^9$),表示需要打印的页码列表。

输出格式

输出一行,包含能够恰好打印列表中所有页面各一次、且不打印其他任何页面的最短打印指令。如果存在多个长度相同的最优解,输出其中任意一个即可。

样例

输入样例 1

15
1 18 20 5 14 11 3 16 17 8 4 10 6 15 21

输出样例 1

11,21,20,14-18,4%10,1#5

说明

样例中给出的答案长度为 23。

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.