問題一覧 > 通常問題

No.205 Merge for the Lexicographically Smallest String

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 181
作問者 : EmKjp
お気に入りにしたユーザー ProblemId : 412 / 自分の提出
問題文最終更新日: 2026-06-25 04:14:03
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.

  1. Initialize the string $T$ to the empty string.
  2. 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.
  3. Append the first character of $S_k$ to the end of the string $T$.
  4. Delete the first character from $S_k$.
  5. Go back to step 2.
Find the lexicographically smallest string among those that can be generated by the merge above.

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もしくは右上の雲マークをクリックしてアカウントを作成してください。