QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#6618. 编码字符串 II

Estadísticas

Tommy 刚刚发明了一种有趣的字符串编码算法,描述如下:

  • 对于任意字符串 $S$,我们可以定义一个字符映射函数 $F_S$,它将 $S$ 中出现的每个字符映射为一个小写字母,定义如下: $$F_S(c) = \text{chr}(G(c, S))$$ 其中 $\text{chr}(i)$ 表示第 $(i+1)$ 个小写拉丁字母,$G(c, S)$ 表示在 $S$ 中字符 $c$ 最后一次出现之后,不同字符的个数。
  • 使用 Tommy 的算法对字符串 $S$ 进行编码时,将 $S$ 中的每个字符 $c$ 同时替换为 $F_S(c)$。

例如,字符串 abc 的编码结果为 cba,字符串 cac 的编码结果为 aba

给定一个长度为 $n$ 的字符串,将其所有的 $2^n - 1$ 个非空子序列进行编码。你的任务是找出所有编码后的字符串中,字典序最大的那一个。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 1000$)。 第二行包含一个长度为 $n$ 的字符串,仅由前 20 个小写字母 at 组成。

输出格式

输出所有编码后的字符串中字典序最大的那一个。

样例

样例输入 1

4
aacc

样例输出 1

bbaa

样例输入 2

4
acac

样例输出 2

bba

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.