626B - Cards - CodeForces Solution


constructive algorithms dp math *1300

Please click on ads to support us..

Python Code:

n=int(input())
s=input()
if len(set(el for el in s))==1:
    print(s[0])
    
 
elif n==1:
    print(s)
elif n==2:
    if "R" not in s:
        print("R")
    elif "G" not in s:
        print("G")
    else :
        print("B")
else :
    
    a=s.count("R")
    b=s.count("G")
    c=s.count("B")
    p=sum(int(el>=2 ) for el in [a,b,c])
    if a and b and c:
        print('BGR')
    elif p>=2:
        print("BGR")
    else :
        if a>1:
            if b or c:
                print("BG")
            else :
                print("R")
        elif b>1:
            if a or c :
                print("BR")
            else :
                print("G")
        else :
            if a or b:
                print("GR")
            else:
                print("B")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  int a;cin>>a;
  string s;cin>>s;
  int g=0,b=0,r=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  if(r>0&&b>0&&g>0)cout<<"BGR";
  else if((r==0&&b>1&&g>1)||(b==0&&r>1&&g>1)||(g==0&&b>1&&r>1))cout<<"BGR";
  else if(r==0&&b==g&&g==1)cout<<"R";
  else if(b==0&&g==r&&r==1)cout<<"B";
  else if(g==0&&b==r&&r==1)cout<<"G";
  else if(b&&r+g==0)cout<<"B";
  else if(r&&b+g==0)cout<<"R";
  else if(g&&r+b==0)cout<<"G";
    
  else if(g>1&&b+r==1){
    cout<<"BR";
  }
  else if(b>1&&g+r==1){
    cout<<"GR";
  }
  else {
    cout<<"BG";
  }
  
  
  
}


Comments

Submit
0 Comments
More Questions

1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets
1703B - ICPC Balloons
1702F - Equate Multisets
1700A - Optimal Path
665C - Simple Strings
1708A - Difference Operations
1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game