CF1108D.Diverse Garland
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is si ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n−1 the condition ti=ti+1 should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
你有一条由 n 盏灯组成的彩灯串。每盏灯的颜色为红色、绿色或蓝色。第 i 盏灯的颜色为 si(其中 'R'、'G' 和 'B' 分别表示彩灯串中各盏灯的颜色)。
你需要重新给这条彩灯串中的某些灯染色(重染一盏灯指将其初始颜色更改为另一种颜色),使得最终得到的彩灯串是多样化的。
若一条彩灯串中任意两个相邻(即位置距离为 1)的灯颜色均不相同,则称该彩灯串是多样化的。
换言之,若最终得到的彩灯串为 t,则对每个从 1 到 n−1 的 i,都应满足 ti=ti+1。
在所有能使初始彩灯串变为多样化彩灯串的重染方案中,你需要选择重染灯数最少的一种方案。若存在多种最优方案,输出任意一种即可。
输入格式
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
输入的第一行包含一个整数 n(1≤n≤2⋅105)—— 灯的数量。
输入的第二行包含一个长度为 n 的字符串 s,由字符 'R'、'G' 和 'B' 组成 —— 表示彩灯串中各灯的颜色。
输出格式
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
在输出的第一行打印一个整数 r —— 将给定花环变为多样花环所需的最少重涂次数。
在输出的第二行打印一个长度为 n 的字符串 t —— 由初始花环经最少次数重涂后得到的一个多样花环。若存在多个最优解,输出任意一个即可。
输入输出样例
输入#1
9 RBGRRBRGG
输出#1
2 RBGRGBRGR
输入#2
8 BBBGBRRR
输出#2
2 BRBGBRGR
输入#3
13 BBRRRRGGGGGRR
输出#3
6 BGRBRBGBGBGRG
输入解题思路,AI测评打分。不知道怎么写?