QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#6617. 编码字符串 I

Statistiques

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$ 的字符串,请对所有 $n$ 个非空前缀进行编码。你的任务是找出所有编码后的字符串中,字典序最大的那一个。

输入格式

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

输出格式

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

样例

输入 1

4
aacc

输出 1

bbaa

输入 2

3
aca

输出 2

ba

说明

在第一个样例中,四个非空前缀 aaaaacaacc 分别被编码为 aaabbabbaa,其中 bbaa 的字典序最大。

在第二个样例中,三个非空前缀 aacaca 分别被编码为 abaaba,其中 ba 的字典序最大。

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.