Codeforces B. Anatoly and Cockroaches
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
string s , s1="" , s2="";
void ek(int len)
{
for(int i=0; i<len; i++)
{
s1 += !(i&1) ? 'r' : 'b';
}
}
void dui(int len)
{
for(int i=0; i<len; i++)
{
s2 += !(i&1) ? 'b' : 'r';
}
}
int main()
{
fast;
int n , len=0 , i , s1r=0, s1b=0, s2r=0, s2b=0 , totals1=0, totals2=0;
while(cin >> n)
{
cin >> s;
len = s.length();
s1 = s2 ="";
s1b = s1r = s2b = s2r = totals1 = totals2 = 0;
ek(len);
dui(len);
//outn(s1); outn(s2);
for(i=0; i<len; i++)
{
if(s[i] != s1[i])
{
if(s[i] == 'r') s1r++;
else s1b++;
}
if(s[i] != s2[i])
{
if(s[i] == 'r') s2r++;
else s2b++;
}
}
if(s1r==0 and s1b==0 or s2r==0 and s2b==0)
{
outn("0");
continue;
}
int couple1 = min(s1r , s1b);
int couple2 = min(s2r , s2b);
int mov1 = (s1r - couple1) + (s1b - couple1) + couple1;
int mov2 = (s2r - couple2) + (s2b - couple2) + couple2;
int ans = min(mov1 , mov2);
outn(ans);
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
string s , s1="" , s2="";
void ek(int len)
{
for(int i=0; i<len; i++)
{
s1 += !(i&1) ? 'r' : 'b';
}
}
void dui(int len)
{
for(int i=0; i<len; i++)
{
s2 += !(i&1) ? 'b' : 'r';
}
}
int main()
{
fast;
int n , len=0 , i , s1r=0, s1b=0, s2r=0, s2b=0 , totals1=0, totals2=0;
while(cin >> n)
{
cin >> s;
len = s.length();
s1 = s2 ="";
s1b = s1r = s2b = s2r = totals1 = totals2 = 0;
ek(len);
dui(len);
//outn(s1); outn(s2);
for(i=0; i<len; i++)
{
if(s[i] != s1[i])
{
if(s[i] == 'r') s1r++;
else s1b++;
}
if(s[i] != s2[i])
{
if(s[i] == 'r') s2r++;
else s2b++;
}
}
if(s1r==0 and s1b==0 or s2r==0 and s2b==0)
{
outn("0");
continue;
}
int couple1 = min(s1r , s1b);
int couple2 = min(s2r , s2b);
int mov1 = (s1r - couple1) + (s1b - couple1) + couple1;
int mov2 = (s2r - couple2) + (s2b - couple2) + couple2;
int ans = min(mov1 , mov2);
outn(ans);
}
return 0;
}
Comments
Post a Comment