QOJ.ac

QOJ

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

#12970. 交换游戏

Statistiques

去年你发明了一种可以用棋盘和骰子玩的游戏,今年你又发明了一种可以用单个字符串玩的新游戏。

游戏开始时有一个包含 $N$ 个小写英文字母('a' 到 'z')的字符串,你可以交换该字符串中的任意两个字符,这个步骤可以执行零次或多次。你的目标是达到字典序最小的字符串。

但最终字符串有一些限制。对于每个位置,它必须是给定字母中的一个(给定字母不一定对每个位置都相同)。例如,第一个位置必须是 'a' 或 'b',第二个位置必须是 'b' 或 'c',依此类推。

注意,这些限制仅针对最终字符串,这意味着你可以进行一些操作,使字符串暂时变为无效,经过后续操作后再变为有效字符串。

给定初始字符串和每个位置的限制,你的任务是编写一个程序,找出经过零次或多次操作后能得到的字典序最小的有效字符串。

注:当比较两个长度相同的不同字符串时,字典序较小的字符串是指在第一个不同的位置上字母较小的那个字符串。

样例

输入格式 1

2
abcde
a
abcde
abcde
abcde
abcde
ab
ab
ab
abcde
abcde

输出格式 1

bacde
NO SOLUTION

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.