CF1063A.Oh Those Palindromes
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一个非空字符串被称为回文串,如果它从左到右读和从右到左读完全相同。例如,“abcba”、“a”和“abba”是回文串,而“abab”和“xy”不是。
一个字符串被称为另一个字符串的子串,如果它可以通过从该字符串的开头和结尾(可能为零个)删除若干字符而得到。例如,“abc”、“ab”和“c”都是字符串“abc”的子串,而“ac”和“d”则不是。
我们定义一个字符串的回文计数为其所有回文子串的个数。例如,字符串“aaa”的回文计数为 6,因为它的所有子串均为回文串;而字符串“abc”的回文计数为 3,因为其中仅有长度为 1 的子串是回文串。
给定一个字符串 s。你可以任意重排其字符。你的目标是得到一个具有最大可能回文计数的字符串。
输入格式
The first line contains an integer n (1≤n≤100000) — the length of string s.
The second line contains string s that consists of exactly n lowercase characters of Latin alphabet.
第一行包含一个整数 n(1≤n≤100000)—— 字符串 s 的长度。
第二行包含字符串 s,该字符串恰好由 n 个小写拉丁字母组成。
输出格式
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.
输出字符串 t,该字符串与字符串 s 包含完全相同的字符集合(且每个字符出现的次数也完全相同)。此外,t 应在所有满足该条件的字符串中具有最大的回文子串数量(palindromic count)。
如果存在多个满足条件的字符串,输出其中任意一个即可。
输入输出样例
输入#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.
在第一个例子中,字符串 “ololo” 有 9 个回文子串:“o”、“l”、“o”、“l”、“o”、“olo”、“lol”、“olo”、“ololo”。注意,尽管某些子串内容相同,但只要它们在原字符串中出现的位置不同,就分别计数。
在第二个例子中,字符串 “abccbaghghghgdfd” 的回文子串总数为 29。
输入解题思路,AI测评打分。不知道怎么写?