Rofyda_Elghadban1

Untitled

Jan 6th, 2024
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.45 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define sz(x) (int)(x.size())
  16.  #define all(v) ((v).begin()), ((v).end())
  17.  #define allr(v) ((v).rbegin()), ((v).rend())
  18.  #define updmax(a,b) a=max(a,b)
  19.  #define updmin(a,b) a=min(a,b)
  20.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  21.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  
  23.  /***********************************************************************************/
  24.  using namespace std;
  25.  void Rofyda_Elghadban(){
  26.   #ifndef ONLINE_JUDGE  
  27.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28.    #endif
  29.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  30.  }
  31.  
  32.  void solve(){
  33.   int n;
  34.   cin>>n;
  35.   string s;
  36.   cin>>s;
  37.   if(n==1){
  38.     cout<<0<<"\n"<<s<<"\n";
  39.     return;
  40.   }
  41.   if(n==2){
  42.     if(s[0]==s[1]){
  43.       cout<<1<<"\n";
  44.       cout<<s[0];
  45.       if(s[0]=='R'){
  46.         cout<<"G"<<"\n";
  47.       }else if(s[0]=='B'){
  48.         cout<<"R"<<"\n";
  49.       }else if(s[0]=='G'){
  50.         cout<<"B"<<"\n";
  51.       }
  52.     }else{
  53.       cout<<0<<"\n"<<s<<"\n";
  54.     }
  55.     return;
  56.   }
  57.   int rgb=0,rbg=0,bgr=0,brg=0,grb=0,gbr=0;
  58.   string rgbs=s,rbgs=s,bgrs=s,brgs=s,grbs=s,gbrs=s;
  59.   /*rgb*/
  60.   map<int,string>mp;
  61.   for(int i=0;i<n;i+=3){
  62.     if(s[i]!='R'){
  63.       rgbs[i]='R';
  64.       rgb++;
  65.     }
  66.     if(s[i+1]!='G'&&i+1<n-1){
  67.       rgbs[i+1]='G';
  68.       rgb++;
  69.     }
  70.     if(s[i+2]!='B'&&i+2<n){
  71.       rgbs[i+2]='B';
  72.       rgb++;
  73.     }
  74.   }
  75.   mp[rgb]=rgbs;
  76.   /*rbg*/
  77.   for(int i=0;i<n;i+=3){
  78.     if(s[i]!='R'){
  79.       rbgs[i]='R';
  80.       rbg++;
  81.     }
  82.     if(s[i+1]!='B'&&i+1<n-1){
  83.       rbgs[i+1]='B';
  84.       rbg++;
  85.     }
  86.     if(s[i+2]!='G'&&i+2<n){
  87.       rbgs[i+2]='G';
  88.       rbg++;
  89.     }
  90.   }
  91.   mp[rbg]=rbgs;
  92.   /*bgr*/
  93.   for(int i=0;i<n;i+=3){
  94.     if(s[i]!='B'){
  95.       bgrs[i]='B';
  96.       bgr++;
  97.     }
  98.     if(s[i+1]!='G'&&i+1<n-1){
  99.       bgrs[i+1]='G';
  100.       bgr++;
  101.     }
  102.     if(s[i+2]!='R'&&i+2<n){
  103.       bgrs[i+2]='R';
  104.       bgr++;
  105.     }
  106.   }
  107.   mp[bgr]=bgrs;
  108.   /*brg*/
  109.   for(int i=0;i<n;i+=3){
  110.     if(s[i]!='B'){
  111.       brgs[i]='B';
  112.       brg++;
  113.     }
  114.     if(s[i+1]!='R'&&i+1<n-1){
  115.       brgs[i+1]='R';
  116.       brg++;
  117.     }
  118.     if(s[i+2]!='G'&&i+2<n){
  119.       brgs[i+2]='G';
  120.       brg++;
  121.     }
  122.   }
  123.   mp[brg]=brgs;
  124.   /*grb*/
  125.   for(int i=0;i<n;i+=3){
  126.     if(s[i]!='G'){
  127.       grbs[i]='G';
  128.       grb++;
  129.     }
  130.     if(s[i+1]!='R'&&i+1<n-1){
  131.       grbs[i+1]='R';
  132.       grb++;
  133.     }
  134.     if(s[i+2]!='B'&&i+2<n){
  135.       grbs[i+2]='B';
  136.       grb++;
  137.     }
  138.   }
  139.   mp[grb]=grbs;
  140.   /*gbr*/
  141.   for(int i=0;i<n;i+=3){
  142.     if(s[i]!='G'){
  143.       gbrs[i]='G';
  144.       gbr++;
  145.     }
  146.     if(s[i+1]!='B'&&i+1<n-1){
  147.       gbrs[i+1]='B';
  148.       gbr++;
  149.     }
  150.     if(s[i+2]!='R'&&i+2<n){
  151.       gbrs[i+2]='R';
  152.       gbr++;
  153.     }
  154.   }
  155.   mp[gbr]=gbrs;
  156.   for(auto &i:mp){
  157.     cout<<i.first<<"\n"<<i.second<<"\n";
  158.     return;
  159.   }
  160.  }
  161.  
  162.  int main(){
  163.   Rofyda_Elghadban();
  164.   // int t;
  165.   // cin>>t;
  166.   // while(t--){
  167.   //   solve();
  168.   // }
  169.   solve();
  170.   return 0;
  171.  }
  172.  
  173.  
Add Comment
Please, Sign In to add comment