Untitled
unknown
plain_text
a month ago
1.7 kB
1
Indexable
Never
#include <bits/stdc++.h> using namespace std ; #define For(n) for(long long i = 0; i < n; i++) #define endl '\n' #define int long long char next (char c){ if(c == 'R')return 'B'; if(c == 'B')return 'G'; return 'R'; } void solve (){ int n;cin>>n; string s;cin>>s; if(n==1||(n==2 && s[0]!=s[1])){ cout << 0 << endl << s << endl; return; } else if(n==2){ cout << 1 << endl<<s[0]<<next(s[0])<< endl; return; } int cnt = 0; for(int i =0 ;i +2 < n ; i++){ if(i>0){ if(s[i+2]!=s[i-1])cnt++; s[i+2] = s[i-1]; } else if(s[i] == s[i+1] && s[i] ==s[i+2]){ cnt+=2; if(i+3<n) s[i] = s[i+3]; if(i+4<n) s[i+1] = s[i+4]; while(s[i] == s[i+1]) s[i+1] = next(s[i+1]); while(s[i+1] == s[i+2] || s[i+2] == s[i]) s[i+2]= next(s[i+2]); } else if(s[i] == s[i+1] ){ cnt ++; while(s[i+1]==s[i]|| s[i+1]==s[i+2]) s[i] = next(s[i]); } else if(s[i] == s[i+2]){ cnt ++; while(s[i+2]==s[i]|| s[i+1]==s[i+2]) s[i+2] = next(s[i+2]); } else if(s[i+1] == s[i+2]){ cnt ++; while(s[i+2]==s[i]|| s[i+1]==s[i+2]) s[i+2] = next(s[i+2]); } } cout << cnt << endl; cout << s << endl; } signed main () { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t =1; // cin>>t; while (t--){ solve(); } }
Leave a Comment