CSES - HIIT Open 2018 - Results
Submission details
Task:Inversions
Sender:Oispa nutellaa
Submission time:2018-05-26 11:29:29 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.02 sdetails

Compiler report

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

Code

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s;

int res = 0;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	res = s.length();
	int cres = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (i%2 == 0 && s[i] != '0') cres++;
		if (i%2 == 1 && s[i] != '1') cres++; 
	}
	res = min(res, cres);
	cres = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (i%2 == 1 && s[i] != '0') cres++;
		if (i%2 == 0 && s[i] != '1') cres++; 
	}
	res = min(res, cres);
	cout << res << "\n";
	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
500000

user output
500000

Test 2

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
500000

user output
500000

Test 3

Verdict: ACCEPTED

input
010101010101010101010101010101...

correct output
0

user output
0

Test 4

Verdict: ACCEPTED

input
101010101010101010101010101010...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
110101011010110100100111110110...

correct output
499476

user output
499476