Longest Palindrome CodeForces - 1304B(思维)
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 $nnn$ distinct strings of equal length $mmm$. 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.
Input
The first line contains two integers $nnn$ and $mmm$ ($1≤n≤1001 \le n \le 1001≤n≤100$, $1≤m≤501 \le m \le 501≤m≤50$) — the number of strings and the length of each string.
Next $nnn$ lines contain a string of length $mmm$ each, consisting of lowercase Latin letters only. All strings are distinct.
Output
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.
Examples
Input
3 3
tab
one
bat
Output
6
tabbat
Input
4 2
oo
ox
xo
xx
Output
6
oxxxxo
Input
3 5
hello
codef
orces
Output
0
Input
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
Output
20
ababwxyzijjizyxwbaba
Note
In the first example, “battab” is also a valid answer.
In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.
In the third example, the empty string is the only valid palindrome string.
在家上課就沒那么多時間寫題了,巨煩!!
雖然是個B題,但是要注意的地方還是挺多的。
錄入一個字符串之后,我們要判斷它的反轉字符串是否存在。但是呢,要注意一點,就是自己是自己的反轉字符串,這樣的情況只能出現一次。但是如果有兩個相同的這樣的串,例如有兩個xx,這就可以都拼接上了,直接暴力就可以。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Longest Palindrome CodeForces - 1304B(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用Python绘制中国新型冠状病毒疫情
- 下一篇: Python实现中文分词--正向最大匹配