D. Diverse Garland
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('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 11) have distinct colors.

In other words, if the obtained garland is tt then for each ii from 11 to n−1n−1 the condition ti≠ti+1ti≠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.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string ss consisting of nn characters 'R', 'G' and 'B' — colors of lamps in the garland.

Output

In the first line of the output print one integer rr — 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 tt of length nn — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples
input

Copy
9
RBGRRBRGG
output

Copy
2
RBGRGBRGR
input

Copy
8
BBBGBRRR
output

Copy
2
BRBGBRGR
input

Copy
13
BBRRRRGGGGGRR
output

Copy
6
BGRBRBGBGBGRG
#include<iostream>
#include<stdio.h>
#include<string.h>
#define maxn 100000000
char str[maxn];
int n ,ans=;
using namespace std;
int main()
{
cin>>n>>str;
for(int i=;i<n-;i++)
{
if(str[i]==str[i+])
{
if(str[i]!='R'&&str[i+]!='R')
str[i+]='R';
else if(str[i]!='G'&&str[i+]!='G')
str[i+]='G';
else if(str[i]!='B'&&str[i+]!='B')
str[i+]='B';
ans++; }
}
cout<<ans<<endl;
for(int i=;i<n;i++)
cout<<str[i];
cout<<endl;
return ; }

D. Diverse Garland-----CF字符串的更多相关文章

  1. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  2. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

  4. D. Diverse Garland

    题意:灯有三种颜色R,G,B.只要同一种颜色相邻就不可以.问最少需要换几次,可以使在一串灯中没有相邻灯的颜色相同. 思路:贪心思路:我们知道一个程序都是要子阶段,然后子阶段各个组合起来形成这个程序.那 ...

  5. CF刷刷水题找自信1

    CF 1108A Two distinct points 题目意思:给你两个线段的起点和终点,让你给出两个不同的点,这两点分别处于两个不同的线段之中.解题思路:题目说如果存在多种可能的点,随意一组答案 ...

  6. 第9周cf刷题(dp)

    Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...

  7. Codeforces-D-Diverse Garland(思维)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  8. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  9. Codeforces Round #535 (Div. 3) 题解

    Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...

随机推荐

  1. SpringMVC——<mvc:annotation-driven/>

    会自动注 册RequestMappingHandlerMapping .RequestMappingHandlerAdapter 与 ExceptionHandlerExceptionResolver ...

  2. 6.python探测Web服务质量方法之pycurl模块

    才开始学习的时候有点忽略了这个模块,觉得既然Python3提供了requests库,为什么多此一举学习这个模块.后来才发现pycurl在探测Web服务器的时候的强大. pycurl是一个用c语言写的l ...

  3. VMware下Ubuntu虚拟机NAT模式 连接Xshell

    1.Edit->Virtual NetWork Editor 2.选择NAT->NAT Settings 配置端口映射关系 很重要! Host port: 真实主机 一般是Windows端 ...

  4. 【Android学习】自定义checkbox

    1.1 自定义checkbox 选中图片 自定义checkbox使用的时android:background而不是android:button,原因在于使用button时自定义图片过大超出边缘部分会截 ...

  5. 微服务linux启动停止脚本

    # 停止脚本#!/bin/bash #其他服务停止脚步可以通过修改APP_MAIN参数即可 APP_MAIN=com.idoipo.infras.eureka.center.Application t ...

  6. log4net工作原理(2)

    上回说道:Repository可以说成基于一个log4net配置节创建的log4net容器,它根据log4net配置节的指示创建其他所有对象(Logger/Appender/Filter/Layout ...

  7. [.net 多线程]ThreadPool的安全机制

    ThreadPool类,有两个方法我们没有用到,UnsafeQueueUserWorkItem 和UnsafeRegisterWaitForSingleObject. 为了完全理解这些方法,首先,我们 ...

  8. 【ARC080F】Prime Flip 差分+二分图匹配

    Description ​ 有无穷个硬币,初始有n个正面向上,其余均正面向下.  你每次可以选择一个奇质数p,并将连续p个硬币都翻转.  问最小操作次数使得所有硬币均正面向下. Input ​ 第一行 ...

  9. linux下用rpm 安装jdk

    转载自http://blog.csdn.net/ldl22847/article/details/7605650 1.下载jdk的rpm安装包,这里以jdk-7u4-linux-i586.rpm为例进 ...

  10. Spring框架的核心模块的作用

    Spring框架由7个定义良好的模块(组件)组成,各个模块可以独立存在,也可以联合使用. (1)Spring Core:核心容器提供了Spring的基本功能.核心容器的核心功能是用Ioc容器来管理类的 ...