Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:23:28
Task:Inversions
Sender:Karhukopla
Submission time:2018-05-26 11:23:28
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.length(); i++) {
                  ~~^~~~~~~~~~~~

Code

#include <bits/stdc++.h>

#define ll long long
#define lll __int128
#define pii pair<int, int>
#define M 1000000007
#define N (1<<20)
using namespace std;

int main () {
	string s;
	cin>>s;
	int b;
	int w;
	b = w = 0;
	for (int i = 0; i < s.length(); i++) {
		int x = s[i] - '0';
		if (x != (i % 2)) b++;
		if (x != 1 - (i % 2)) w++;
	}
	cout<<min(b, w)<<endl;
}