はまやんはまやんはまやん

hamayanhamayan's blog

Coloring Colorfully [AtCoder Beginner Contest 124 C]

https://atcoder.jp/contests/abc124/tasks/abc124_c

解説

https://atcoder.jp/contests/abc124/submissions/4963281

最終的な形は「101010...」か「010101...」しかないので、どちらも試す。
最終的な目標と違っている個数分だけ塗り替えが必要なので、その塗り替え回数が小さい方が答え。

string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
 
	int ans = inf;
	int N = S.length();
 
	// 10101...
	{
		int cnt = 0;
		rep(i, 0, N) if ((S[i] - '0') == i % 2) cnt++;
		chmin(ans, cnt);
	}
 
	// 01010...
	{
		int cnt = 0;
		rep(i, 0, N) if ((S[i] - '0') != i % 2) cnt++;
		chmin(ans, cnt);
	}
 
	cout << ans << endl;
}