#P10244. String Minimization
String Minimization
Problem Description
You are given four strings , each of length . You may perform the following operation any number of times:
- Choose an index , swap and , then swap and .
Find the lexicographically smallest possible string , under the condition that the resulting string is as lexicographically small as possible.
If you do not know what lexicographical order is, see below:
For two strings , we say is lexicographically smaller than (written as ) if and only if there exists a non-negative integer such that the first characters of and are the same, and the ASCII code of is smaller than that of .
For example:
- (when )
- (when ).
Input Format
The first line contains a positive integer , the length of strings .
The next four lines each contain a string, representing respectively.
Output Format
Output one line containing a string, the required string .
8
westlake
yummyqaq
weabzzke
azazazaq
auazyqaq
Hint
[Sample Explanation]
Choosing as can make reach the minimum lexicographical order . At this time, string also becomes the minimum lexicographical order that satisfies the requirement, which is .
In fact, if we do not operate when , the lexicographical order of is still minimal, but then string would be , which is not small enough.
[Constraints]
This problem has test points, each worth points.
| Test Point ID | Special Property | |
|---|---|---|
For all testdata, it is guaranteed that , and all characters in the strings are lowercase letters.
Translated by ChatGPT 5