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. Logistic Regression 用于预测马是否生病

    1.利用Logistic regression 进行分类的主要思想 根据现有数据对分类边界线建立回归公式,即寻找最佳拟合参数集,然后进行分类. 2.利用梯度下降找出最佳拟合参数 3.代码实现 # -* ...

  2. c++(重载等号=操作为深拷贝)

    // ConsoleApplication19.cpp : 定义控制台应用程序的入口点. // #pragma warning(disable:4996) #include "stdafx. ...

  3. 使用UpdatePanel时FileUpload失效的问题!【FileUpload上传文件失败】

    1.使用UpdatePanel后,FileUpload的HasFile始终为false,无论你是否选中了上传文件! 方案一:设置ScriptManager 的EnablePartialRenderin ...

  4. Media Queries 媒体类型

    引用方法:1.<link rel="stylesheet" type="text/css" href="style.css" medi ...

  5. 《the art of software testing》第四章 测试用例的设计

    白盒测试 逻辑覆盖测试: 逻辑覆盖是以程序内部的逻辑结构为基础的设计测试用例的技术.它属白盒测试.白盒测试的测试方法有代码检查法.静态结构分析法.静态质量度量法.逻辑覆盖法.基本路径测试法.域测试.符 ...

  6. Robot Framework - 基础关键字 BuiltIn 库(一)

    今天给大家分享的是Robot Framework 机器人框架中 BuiltIn 基础库的使用...BuiltIn 库里面提供了很多基础方法助力于我们在自动化测试领域中做的更好!——本系列教程是教会大家 ...

  7. [转]FreeMarker使用

    copy自http://demojava.iteye.com/blog/800204 以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主 ...

  8. FileUtils 文件下载 文件导出

    public class FileUtils { /// <summary> /// 文件下载 /// </summary> /// <param name=" ...

  9. repeater+aspnetpager 组合分页

    页面代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TF_Product. ...

  10. 十五、Node.js-fs模块(中)

    有了上一篇JS同步异步知识的铺垫,我们一起学习一下fs模块的同步和异步知识: Node.js内置的fs模块就是文件系统模块,负责读写文件. 和所有其它JavaScript模块不同的是,fs模块同时提供 ...