Code Submission Evaluation System Login

HIIT Open 2018

Start:2018-05-26 11:00:00
End:2018-05-26 16:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - HIIT Open 2018 - Results
History
2018-05-26 12:09:34
Task:Inversions
Sender:DualCore
Submission time:2018-05-26 12:09:34
Language:C++
Status:READY
Result:ACCEPTED

Test results

testverdicttime (s)
#1ACCEPTED0.04 / 1.00details
#2ACCEPTED0.03 / 1.00details
#3ACCEPTED0.05 / 1.00details
#4ACCEPTED0.06 / 1.00details
#5ACCEPTED0.04 / 1.00details

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...
view   save

correct output
500000
view   save

user output
500000
view   save

Test 2

Verdict: ACCEPTED

input
111111111111111111111111111111...
view   save

correct output
500000
view   save

user output
500000
view   save

Test 3

Verdict: ACCEPTED

input
010101010101010101010101010101...
view   save

correct output
0
view   save

user output
0
view   save

Test 4

Verdict: ACCEPTED

input
101010101010101010101010101010...
view   save

correct output
0
view   save

user output
0
view   save

Test 5

Verdict: ACCEPTED

input
110101011010110100100111110110...
view   save

correct output
499476
view   save

user output
499476
view   save