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$이 이 순서대로 주어진다. ($2 \le N \le 2000, 1 \le M \le 2000$)

이어지는 $N$개의 줄에는 각각 소문자 영어 알파벳으로 구성된 길이 $M$의 문자열 $S_i$가 주어진다.

출력

정답을 출력하라.

예제

입력 1

2 3
cat
cut

출력 1

atc

참고

첫 번째 예제에서, 처음에 $X = \text{cat}$이다. 첫 번째 연산에서 $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.