#abc268d. D - Unique Username
D - Unique Username
Score : points
问题描述
高桥在为一个服务选择用户名时遇到了困难。编写一段代码来帮助他。
找出满足以下所有条件的字符串 :
- 是通过以下步骤获取的:
- 让 成为 的一个排列。按照顺序,令 为 、(1个或多个
_
符号)、、(1个或多个_
符号)、、(1个或多个_
符号)以及 的连接。
- 让 成为 的一个排列。按照顺序,令 为 、(1个或多个
- 字符串 的长度在 到 之间(包括两端点)。
- 不与给定的 个字符串 中的任何一个相等。
如果不存在满足所有条件的 ,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is having trouble with deciding a username for a service. Write a code to help him.
Find a string that satisfies all of the following conditions:
- is obtained by the following procedure:
- Let be a permutation of . Let be the concatenation of , ( or more copies of
_
), , ( or more copies of_
), , ( or more copies of_
), and , in this order.
- Let be a permutation of . Let be the concatenation of , ( or more copies of
- The length of is between and , inclusive.
- does not coincide with any of strings .
If there is no that satisfies all of the conditions, print -1
instead.
Constraints
- and are integers.
- if .
- is a string consisting of lowercase English letters.
- if .
- is a string consisting of lowercase English letters and
_
.
Input
Input is given from Standard Input in the following format:
Output
Print a string that satisfies all of the conditions. If there is no that satisfies all of the conditions, print -1
instead.
If there are multiple solutions, print any of them.
Sample Input 1
1 1
chokudai
chokudai
Sample Output 1
-1
The only string that satisfies the first and second conditions is chokudai
, but it coincides with .
Thus, there is no that satisfies all of the conditions, so -1
should be printed.
Sample Input 2
2 2
choku
dai
chokudai
choku_dai
Sample Output 2
dai_choku
Strings like choku__dai
(which has two _
's between choku
and dai
) also satisfy all of the conditions.
Sample Input 3
2 2
chokudai
atcoder
chokudai_atcoder
atcoder_chokudai
Sample Output 3
-1
chokudai__atcoder
and atcoder__chokudai
(which have two _
's between chokudai
and atcoder
) have a length of , which violates the second condition.
Sample Input 4
4 4
ab
cd
ef
gh
hoge
fuga
____
_ab_cd_ef_gh_
Sample Output 4
ab__ef___cd_gh
The given may contain a string that cannot be obtained by the procedure described in the first condition.
update @ 2024/3/10 11:18:23