日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Longest Palindrome CodeForces - 1304B(思维)

發(fā)布時間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Longest Palindrome CodeForces - 1304B(思维) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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 1001n100$, $1≤m≤501 \le m \le 501m50$) — 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題,但是要注意的地方還是挺多的。
錄入一個字符串之后,我們要判斷它的反轉(zhuǎn)字符串是否存在。但是呢,要注意一點,就是自己是自己的反轉(zhuǎn)字符串,這樣的情況只能出現(xiàn)一次。但是如果有兩個相同的這樣的串,例如有兩個xx,這就可以都拼接上了,直接暴力就可以。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=101; string s[maxx]; map<string,int>mp; int n,m;int main() {cin>>n>>m;mp.clear();string t1="",t2="";for(int i=0;i<n;i++) cin>>s[i],mp[s[i]]++;string x;int flag=0;for(int i=0;i<n;i++){x=s[i];reverse(s[i].begin(),s[i].end());swap(x,s[i]);if(mp[s[i]]<=0) continue;if(mp[x]){if(x==s[i]&&mp[x]==1&&flag==0) t1=t1+x,flag=1,mp[x]--;else if(x!=s[i]||(x==s[i]&&mp[x]>1))t1=s[i]+t1,t2=t2+x,mp[x]--,mp[s[i]]--;}}t1=t1+t2;cout<<t1.length()<<endl;cout<<t1<<endl;return 0; }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的Longest Palindrome CodeForces - 1304B(思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。