CSES - HIIT Open 2018 - Results
Submission details
Task:Inversions
Sender:DualCore
Submission time:2018-05-26 12:09:34
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.04 sdetails

Compiler report

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

Code

/*
 * main.cpp
 *
 *  Created on: May 26, 2018
 *      Author: guest132
 */

#include <iostream>
#include <string>
#include <cmath>

int main()
{
	std::string input;
	std::getline(std::cin, input);


	int count1 = 0;
	for (int i = 0; i < input.length() - 1; ++i)
	{
			int L = 0;
			int R = input[i] - '0';
			if (L != R)
				++count1;
			++i;
			L = 1;
			R = input[i] - '0';
			if (L != R)
				++count1;
	}
	if (input.length() % 2 == 1)
	{
		int L = 0;
		int R = input[input.length() - 1] - '0';
		if (L != R)
			++count1;
	}

	int count2 = 0;
	for (int i = 0; i < input.length() - 1; ++i)
	{
			int L = 1;
			int R = input[i] - '0';
			if (L != R)
				++count2;
			++i;
			L = 0;
			R = input[i] - '0';
			if (L != R)
				++count2;
	}
	if (input.length() % 2 == 1)
	{
		int L = 1;
		int R = input[input.length() - 1] - '0';
		if (L != R)
			++count2;
	}

	std::cout << std::min(count1, count2);
}

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