Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define pi 3.141592654
- #define NUM 1e18
- #define Mod 1'000'000'007
- #define fixed(n) fixed<<setprecision(n)
- #define cin(v) for(auto &i:v) cin >> i ;
- #define cout(v) for(auto &i:v) cout << i <<" ";
- #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
- #define small(x) (x>=97&&x<=122)
- #define capital(x) (x>=65&&x<=90)
- #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
- #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
- #define sz(x) (int)(x.size())
- #define all(v) ((v).begin()), ((v).end())
- #define allr(v) ((v).rbegin()), ((v).rend())
- #define updmax(a,b) a=max(a,b)
- #define updmin(a,b) a=min(a,b)
- #define ceil(a,b) ((a/b)+(a%b?1:0))
- /* asc -> 1 2 3 ,des -> 3 2 1 */
- /***********************************************************************************/
- using namespace std;
- void Rofyda_Elghadban(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- }
- void solve(){
- int n;
- cin>>n;
- string s;
- cin>>s;
- if(n==1){
- cout<<0<<"\n"<<s<<"\n";
- return;
- }
- if(n==2){
- if(s[0]==s[1]){
- cout<<1<<"\n";
- cout<<s[0];
- if(s[0]=='R'){
- cout<<"G"<<"\n";
- }else if(s[0]=='B'){
- cout<<"R"<<"\n";
- }else if(s[0]=='G'){
- cout<<"B"<<"\n";
- }
- }else{
- cout<<0<<"\n"<<s<<"\n";
- }
- return;
- }
- int rgb=0,rbg=0,bgr=0,brg=0,grb=0,gbr=0;
- string rgbs=s,rbgs=s,bgrs=s,brgs=s,grbs=s,gbrs=s;
- /*rgb*/
- map<int,string>mp;
- for(int i=0;i<n;i+=3){
- if(s[i]!='R'){
- rgbs[i]='R';
- rgb++;
- }
- if(s[i+1]!='G'&&i+1<n-1){
- rgbs[i+1]='G';
- rgb++;
- }
- if(s[i+2]!='B'&&i+2<n){
- rgbs[i+2]='B';
- rgb++;
- }
- }
- mp[rgb]=rgbs;
- /*rbg*/
- for(int i=0;i<n;i+=3){
- if(s[i]!='R'){
- rbgs[i]='R';
- rbg++;
- }
- if(s[i+1]!='B'&&i+1<n-1){
- rbgs[i+1]='B';
- rbg++;
- }
- if(s[i+2]!='G'&&i+2<n){
- rbgs[i+2]='G';
- rbg++;
- }
- }
- mp[rbg]=rbgs;
- /*bgr*/
- for(int i=0;i<n;i+=3){
- if(s[i]!='B'){
- bgrs[i]='B';
- bgr++;
- }
- if(s[i+1]!='G'&&i+1<n-1){
- bgrs[i+1]='G';
- bgr++;
- }
- if(s[i+2]!='R'&&i+2<n){
- bgrs[i+2]='R';
- bgr++;
- }
- }
- mp[bgr]=bgrs;
- /*brg*/
- for(int i=0;i<n;i+=3){
- if(s[i]!='B'){
- brgs[i]='B';
- brg++;
- }
- if(s[i+1]!='R'&&i+1<n-1){
- brgs[i+1]='R';
- brg++;
- }
- if(s[i+2]!='G'&&i+2<n){
- brgs[i+2]='G';
- brg++;
- }
- }
- mp[brg]=brgs;
- /*grb*/
- for(int i=0;i<n;i+=3){
- if(s[i]!='G'){
- grbs[i]='G';
- grb++;
- }
- if(s[i+1]!='R'&&i+1<n-1){
- grbs[i+1]='R';
- grb++;
- }
- if(s[i+2]!='B'&&i+2<n){
- grbs[i+2]='B';
- grb++;
- }
- }
- mp[grb]=grbs;
- /*gbr*/
- for(int i=0;i<n;i+=3){
- if(s[i]!='G'){
- gbrs[i]='G';
- gbr++;
- }
- if(s[i+1]!='B'&&i+1<n-1){
- gbrs[i+1]='B';
- gbr++;
- }
- if(s[i+2]!='R'&&i+2<n){
- gbrs[i+2]='R';
- gbr++;
- }
- }
- mp[gbr]=gbrs;
- for(auto &i:mp){
- cout<<i.first<<"\n"<<i.second<<"\n";
- return;
- }
- }
- int main(){
- Rofyda_Elghadban();
- // int t;
- // cin>>t;
- // while(t--){
- // solve();
- // }
- solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment