You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 50;
char str[N];
int main() {
int n, ans = 0;
scanf("%d%s", &n, str);
for (int i = 1; i < n - 1; i++) {
if (str[i - 1] == str[i]) {
if (str[i - 1] == 'R' && str[i + 1] == 'G' || str[i - 1] == 'G' && str[i + 1] == 'R')
str[i] = 'B';
else if (str[i - 1] == 'B' && str[i + 1] == 'G' || str[i - 1] == 'G' && str[i + 1] == 'B')
str[i] = 'R';
else if (str[i - 1] == 'B' && str[i + 1] == 'R' || str[i - 1] == 'R' && str[i + 1] == 'B')
str[i] = 'G';
else if (str[i - 1] == 'B' && str[i + 1] == 'B')
str[i] = 'R';
else if (str[i - 1] == 'R' && str[i + 1] == 'R')
str[i] = 'G';
else if (str[i - 1] == 'G' && str[i + 1] == 'G')
str[i] = 'R';
ans++;
}
}
if (str[n - 1] == str[n - 2]) {
str[n - 1] = "RG"[str[n - 1] != 'G'];
ans++;
}
printf("%d\n%s", ans, str);
return 0;
}