Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

長さ $M$ の小文字の英字からなる $N$ 個の文字列 $S_1, \dots, S_N$ が与えられます。 最初、$X = S_1$ とし、$N - 1$ 回の操作を行います。 $i$ 番目の操作では、$X$ と $S_{i+1}$ をこの順で連結してできる文字列を $Y$ とします。次に、$Y$ の長さ $M$ の連続する部分文字列を任意に選び、$X$ をその部分文字列で置き換えます。 最終的な $X$ としてあり得る辞書順最小の文字列を出力してください。

入力

入力は以下の形式で与えられます。

$N$ $M$ $S_1$ $S_2$ $\vdots$ $S_N$

制約:

  • $2 \le N \le 2000$
  • $1 \le M \le 2000$
  • $S_i$ は長さ $M$ の小文字の英字からなる文字列である。

出力

答えを出力してください。

入出力例

入力 1

2 3
cat
cut

出力 1

atc

注記

最初の例では、最初 $X = \text{cat}$ です。 1回目の操作では、$Y = \text{catcut}$ となります。2文字目から4文字目までの連続する部分文字列を選ぶと、$X = \text{atc}$ となり、これが辞書順最小となります。

入力 2

2 1
a
b

出力 2

a

入力 3

3 8
jastaway
tatesoto
soryuusi

出力 3

asoryuus

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1629EditorialOpenO(n^3 log \sum /w) 做法tzl_Dedicatus5452026-04-27 11:23:46View
#1523EditorialOpen题解jiangly2026-04-15 16:03:12View
#1506EditorialOpenO(n^3) 做法incent2026-04-12 21:25:08View

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.