758B - Blown Garland - CodeForces Solution


brute force implementation number theory *1100

Please click on ads to support us..

Python Code:

import math

def _input(): return map(int, input().split())

s = input()
res = [0]*4
i=0
ss = ''
while i<len(s) and len(ss)<4:
    if s[i]!='!': ss += s[i]
    else:
        j = i+4
        while j<len(s) and s[j]=='!': j+=4
        ss+=s[j]
    i+=1

for i in range(len(s)): 
    if s[i]=='!': 
        k = ss[i%4]
        if k == 'R': res[0]+=1
        if k=='B': res[1]+=1
        if k=='Y': res[2]+=1
        if k=='G': res[3]+=1
print(*res)


        
        

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define INF 9999
#define F first
#define S second
#define pb(x)  push_back(x)
#define vi  vector<int> 
#define vstr vector<string>
#define pii  pair<int,int>
#define all(x)  (x).begin(),(x).end()
typedef long long ll;
void solve() {
    string str;
    cin>>str;
    map<int,char> m;
    for(int i=0;i<str.length();i++) {
        if(str[i] == 'G') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'R') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'Y') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'B'){
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        if(m.size() == 4) break;
    }
    map<char,int> n;
    for(int i=0;i<str.length();i++) {
        if(str[i] == '!') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            char col=m[pos];
            n[col]++;
        }
    }
    int ky=0,kb=0,kr=0,kg=0;
    ky=n['Y'];
    kg=n['G'];
    kb=n['B'];
    kr=n['R'];
    cout<<kr<<" "<<kb<<" "<<ky<<" "<<kg<<endl;
    return ;
}
int main() {
    solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1225A - Forgetting Things
1717A - Madoka and Strange Thoughts
1717B - Madoka and Underground Competitions
61B - Hard Work
959B - Mahmoud and Ehab and the message
802G - Fake News (easy)
1717C - Madoka and Formal Statement
420A - Start Up
1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban
1585C - Minimize Distance
1506E - Restoring the Permutation
1539A - Contest Start
363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys
1725A - Accumulation of Dominoes
1675E - Replace With the Previous Minimize
839A - Arya and Bran
16B - Burglar and Matches
1625B - Elementary Particles
1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation