CF1165C.Good String
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.
You are given a string s, you have to delete minimum number of characters from this string so that it becomes good.
我们(再次)称一个字符串为“好字符串”,如果它的长度为偶数,且该字符串中每个奇数位置上的字符都与其后一个字符不同(即第一个字符不同于第二个字符,第三个字符不同于第四个字符,依此类推)。例如,字符串 good、string 和 xyyx 是好字符串,而字符串 bad、aa 和 aabc 不是好字符串。注意:空字符串被视为好字符串。
给定一个字符串 s,你需要从中删除最少数量的字符,使得它变成一个好字符串。
输入格式
The first line contains one integer n (1≤n≤2⋅105) — the number of characters in s.
The second line contains the string s, consisting of exactly n lowercase Latin letters.
第一行包含一个整数 n(1≤n≤2⋅105)—— 字符串 s 的字符个数。
第二行包含字符串 s,恰好由 n 个小写拉丁字母组成。
输出格式
In the first line, print one integer k (0≤k≤n) — the minimum number of characters you have to delete from s to make it good.
In the second line, print the resulting string s. If it is empty, you may leave the second line blank, or not print it at all.
第一行,输出一个整数 k(0≤k≤n)—— 即从字符串 s 中删除以使其变为“好字符串”所需的最少字符个数。
第二行,输出处理后的字符串 s。若结果为空字符串,你可以留空第二行,或完全不输出第二行。
输入输出样例
输入#1
4 good
输出#1
0 good
输入#2
4 aabc
输出#2
2 ab
输入#3
3 aaa
输出#3
3
输入解题思路,AI测评打分。不知道怎么写?