307121: CF1304B. Longest Palindrome
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Longest Palindrome
题意翻译
- 给你 $n$ 个长度为 $m$ 的字符串。 - 请你判断删去其中的几个(或者不删去),能使得将剩下字符串随意排列所形成的回文串长度最大。 - 请你输出最大的长度和那个回文串。 - $1\le n\le 100$,$1\le m\le 50$。 - translate by @[ShineEternal](https://www.luogu.com.cn/user/45475)。题目描述
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome. Gildong loves this concept so much, so he wants to play with it. He has $ n $ distinct strings of equal length $ m $ . He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.输入输出格式
输入格式
The first line contains two integers $ n $ and $ m $ ( $ 1 \le n \le 100 $ , $ 1 \le m \le 50 $ ) — the number of strings and the length of each string. Next $ n $ lines contain a string of length $ m $ each, consisting of lowercase Latin letters only. All strings are distinct.
输出格式
In the first line, print the length of the longest palindrome string you made. In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all.
输入输出样例
输入样例 #1
3 3
tab
one
bat
输出样例 #1
6
tabbat
输入样例 #2
4 2
oo
ox
xo
xx
输出样例 #2
6
oxxxxo
输入样例 #3
3 5
hello
codef
orces
输出样例 #3
0
输入样例 #4
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
输出样例 #4
20
ababwxyzijjizyxwbaba