No.205 Merge for the Lexicographically Smallest String
レベル :
/ AI推定難易度 : 1400
/ 実行時間制限 : 1ケース 5.000秒 / メモリ制限
: 512 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 181
作問者 :
EmKjp
タグ : / 解いたユーザー数 181
作問者 :
EmKjp
問題文最終更新日: 2026-06-25 04:14:03
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 103
(順位表)
の他の問題:
Problem Statement
You are given N strings $S_1, ..., S_N$. Merge these strings into one string using the following procedure.
- Initialize the string $T$ to the empty string.
- Choose any one non-empty string $S_k$ from $S_1, ..., S_N$. If no such string exists, return the string $T$ as the result and terminate.
- Append the first character of $S_k$ to the end of the string $T$.
- Delete the first character from $S_k$.
- Go back to step 2.
Input
$N$ $S_1$ $S_2$ ... $S_N$
$1 \le N \le 50$
$1 \le |S_i| \le 50$ ($1 \le i \le N$)
Each string $S_i$ consists of lowercase English letters ('a'-'z').
Output
Output the lexicographically smallest string among those that can be generated by the merge. Print a newline at the end.
Sample
Sample 1
Input
1 abc
Output
abc
Since there is only one string, "abc" is the only string that can be obtained by merging.
Sample 2
Input
2 ac bd
Output
abcd
The strings that can be generated are the six strings "abcd", "abdc", "acbd", "bacd", "badc", and "bdac", and the lexicographically smallest of them is "abcd".
Sample 3
Input
5 one two three four five
Output
ffioneothreeturvewo
Sample 4
Input
2 az za
Output
azaz
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。