A12079 | Oh Those Palindromes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.
A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not.
Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is $6$ because all its substrings are palindromes, and the palindromic count of the string "abc" is $3$ because only its substrings of length $1$ are palindromes.
You are given a string $s$ . You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count.
A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not.
Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is $6$ because all its substrings are palindromes, and the palindromic count of the string "abc" is $3$ because only its substrings of length $1$ are palindromes.
You are given a string $s$ . You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count.
输入格式
The first line contains an integer $n$ ( $1 \le n \le 100\,000$ ) — the length of string $s$ .
The second line contains string $s$ that consists of exactly $n$ lowercase characters of Latin alphabet.
The second line contains string $s$ that consists of exactly $n$ lowercase characters of Latin alphabet.
输出格式
Print string $t$ , which consists of the same set of characters (and each characters appears exactly the same number of times) as string $s$ . Moreover, $t$ should have the maximum possible value of palindromic count among all such strings strings.
If there are multiple such strings, print any of them.
If there are multiple such strings, print any of them.
输入输出样例
输入 #1
5 oolol
输出 #1
ololo
输入 #2
16 gagadbcgghhchbdf
输出 #2
abccbaghghghgdfd
In the first example, string "ololo" has $9$ palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string.
In the second example, the palindromic count of string "abccbaghghghgdfd" is $29$ .
In the second example, the palindromic count of string "abccbaghghghgdfd" is $29$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted