CF1304B.Longest Palindrome
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
回到解题环节,吉隆东正在学习回文串的相关知识。他了解到:回文串是指与其逆序字符串完全相同的字符串。例如,“pop”、“noon”、“x”和“kkkkkk”都是回文串,而“moon”、“tv”和“abab”则不是回文串。空字符串也被视为回文串。
吉隆东非常喜爱这一概念,因此想用它来玩一个游戏。他有 n 个长度均为 m 的互不相同的字符串。他希望丢弃其中一部分字符串(也可以一个都不丢弃,或者全部丢弃),并对剩余的字符串重新排序,使得它们按序拼接后构成一个回文串。此外,他还希望这个回文串的长度尽可能长。请帮助他找出这样一个回文串。
输入格式
The first line contains two integers n and m (1≤n≤100, 1≤m≤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.
第一行包含两个整数 n 和 m(1≤n≤100,1≤m≤50)—— 分别表示字符串的个数以及每个字符串的长度。
接下来的 n 行,每行包含一个长度为 m 的字符串,仅由小写拉丁字母组成。所有字符串互不相同。
输出格式
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
说明/提示
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.
在第一个例子中,“battab”也是一个有效的答案。
在第二个例子中,包括样例输出在内,共有 4 种不同的有效答案。我们不会提示其余答案是什么。
在第三个例子中,空字符串是唯一有效的回文字符串。
输入解题思路,AI测评打分。不知道怎么写?