A13181 | Longest Palindrome
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
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
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted