CSES - Datatähti 2016 alku - Results
Submission details
Task:Bittipeli
Sender:tomivah
Submission time:2015-10-10 20:11:36
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool solve(std::vector<long long unsigned int>&, std::vector<long long unsigned int>&, long long unsigned int)':
input/code.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for ( int i = 0; i < moves.size(); ++i )
                      ^
input/code.cpp:35:10: error: no match for 'operator+=' (operand types are 'std::vector<long long unsigned int>' and 'std::vector<long long unsigned int>::size_type {aka long unsigned int}')
    moves += segmentLengths.size();
          ^
input/code.cpp:37:62: error: expected ';' before ')' token
    for ( unsigned long long i = 0; i < segmentLengths.size() )
                                                              ^
input/code.cpp:44:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for ( int i = 0; i < moves.size(); ++i )
                       ^

Code

#include <iostream>
#include <string>
#include <vector>

bool solve( std::vector< unsigned long long >& segmentLengths, std::vector< unsigned long long >& moves, unsigned long long moveCount )
{
	if ( segmentLengths.size() == 1 )
	{
		moveCount++;
		moves.push_back( 1 );
		std::cout << moveCount << "\n";

		for ( int i = 0; i < moves.size(); ++i )
		{
			std::cout << moves.at( i ) << " ";
		}

		std::cout << "\n";
		return true;
	}
	else
	{
		bool canSolve = true;

		for ( unsigned long long i = 0; i < segmentLengths.size(); ++i )
		{
			if ( segmentLengths.size() == 1 )
			{
				canSolve = false;
			}
		}

		if ( canSolve )
		{
			moves += segmentLengths.size();

			for ( unsigned long long i = 0; i < segmentLengths.size() )
			{
				moves.push_back( 1 );
			}

				std::cout << moveCount << "\n";

			for ( int i = 0; i < moves.size(); ++i )
			{
				std::cout << moves.at( i ) << " ";
			}

			std::cout << "\n";
			return true;
		}

		int segment = 1;

		for ( unsigned long long i = 0; i < segmentLengths.size(); ++i )
		{
			if ( segmentLengths.at( i ) > 1 )
			{
				std::vector< unsigned long long > newSegments( segmentLengths );

				if ( i > 0 && i < segmentLengths.size() - 1 )
				{
					newSegments.at( i - 1 ) += newSegments.at( i + 1 );
					newSegments.erase( newSegments.begin() + i );
				}

				newSegments.erase( newSegments.begin() + i );

				if ( moves.size() > moveCount )
				{
					moves[ moveCount ] = segment;
				}
				else
				{
					moves.push_back( segment );
				}

				if ( solve( newSegments, moves, moveCount + 1 ) )
				{
					return true;
				}

				segment++;
			}
		}
	}

	return false;
}

int main()
{
	std::ios_base::sync_with_stdio( false );

	std::vector< unsigned long long > segmentLengths;
	std::string input;
	std::getline( std::cin, input );

	bool lastBit = 0;
	unsigned long long segmentLength = 1;

	for ( unsigned long long i = 0; i < input.length(); ++i )
	{
		if ( i > 0 )
		{
			if ( lastBit == ( input[ i ] == '1' ) )
			{
				segmentLength++;
			}
			else
			{
				segmentLengths.push_back( segmentLength );
				segmentLength = 1;
			}
		}
		
		lastBit = input[ i ] == '1';
	}

	segmentLengths.push_back( segmentLength );

	std::vector< unsigned long long > moves;

	if ( !solve( segmentLengths, moves, 0 ) )
	{
		std::cout << "QAQ\n";
	}
	
	return 0;
}