719B - Anatoly and Cockroaches - CodeForces Solution


greedy *1400

Please click on ads to support us..

Python Code:

input()
S=4*[0]
e=0
for c in input():
	S[e|('r'!=c)<<1]+=1
	e=not e
print(min(max(S[0],S[3]),max(S[1],S[2])))

C++ Code:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb push_back
#define endl "\n";
#define maxii 300005
using namespace std;
inline int setBit(int N, int pos) { return N = N | (1 << pos); }
inline int toggleBit(int N, int pos) { return N = (N ^ (1 << pos)); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi[maxii];
vector<int>:: iterator child;
vector<int>vi2[maxii];
vector<int>vi3[maxii];
vector<lln> vl;
vector<vector<pair<int, int> > > vii;
//vector<pii> vii;
vector<pll> vll;
using namespace __gnu_pbds;
//using namespace std;
typedef tree<pll, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
//ordered_set st;
//ordered_set :: iterator it;
//vii.clear();
//vii.resize(n + 1);
/* 1)find a small value than x for pbds st.order_of_key(x)
   2)find a number by position st.find_by_order(2)
   3)delete st.erase(st.find_by_order(st.order_of_key(tas2)));*/


int arr[maxii];
int arr2[4*maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;

string s;

int dp[maxii][2];



int main()
{
    //ios_base::sync_with_stdio(false);
   // cin.tie(NULL),cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int test=1;
   // sc(test)
    for(int xx=1;xx<=test;xx++)
    {
        sc(n)
        //string a;
        cin>>s;
        int a=0,b=0,c=0,d=0;
        for(int i=0;i<n;i++)
        {
            if(i%2==1 && s[i]!='b')a++;
            if(i%2==0 && s[i]!='r')c++;
        }
        int ans1=max(a,c);

        for(int i=0;i<n;i++)
        {
            if(i%2==0 && s[i]!='b')b++;
            if(i%2==1 && s[i]!='r')d++;
        }
        int ans2=max(b,d);
        cout<<min(ans1,ans2);




    }


}


Comments

Submit
0 Comments
More Questions

2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome
851A - Arpa and a research in Mexican wave
811A - Vladik and Courtesy
1006B - Polycarp's Practice
1422A - Fence
21D - Traveling Graph
1559B - Mocha and Red and Blue
1579C - Ticks
268B - Buttons
898A - Rounding
1372B - Omkar and Last Class of Math