Advertisement
Rofyda_Elghadban1

Untitled

Jan 6th, 2024
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 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,counter=0;
  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"<<s[0];
  44.       if(s[0]=='R'){
  45.         cout<<"G"<<"\n";
  46.       }else if(s[0]=='G'){
  47.         cout<<"B"<<"\n";
  48.       }else if(s[0]=='B'){
  49.         cout<<"R"<<"\n";
  50.       }
  51.     }else if(s[0]!=s[1]){
  52.       cout<<0<<"\n"<<s<<"\n";
  53.     }
  54.     return;
  55.   }
  56.   string t="RGB";
  57.   sort(all(t));
  58.   map<int,string>mp;
  59.   string ss=s;
  60.   while(next_permutation(t.begin(),t.end())){
  61.     for(int i=0;i<n;i+=3){
  62.       if(s[i]!=t[0]){
  63.         ss[i]=t[0];
  64.         counter++;
  65.       }
  66.       if(s[i+1]!=t[1]&&i+1<n-1){
  67.         ss[i+1]=t[1];
  68.         counter++;
  69.       }
  70.       if(s[i+2]!=t[2]&&i+2<n){
  71.         ss[i+2]=t[2];
  72.         counter++;
  73.       }
  74.     }
  75.     mp[counter]=ss;
  76.     ss=s;
  77.     counter=0;
  78.   }
  79.   for(auto &i:mp){
  80.     cout<<i.first<<"\n"<<i.second<<"\n";
  81.     return;
  82.   }
  83.  }
  84.  
  85.  int main(){
  86.   Rofyda_Elghadban();
  87.   // int t;
  88.   // cin>>t;
  89.   // while(t--){
  90.   //   solve();
  91.   // }
  92.   solve();
  93.   return 0;
  94.  }
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement