CSES - Datatähti 2017 loppu - Results
Submission details
Task:Ohjelma
Sender:kapesu8
Submission time:2017-01-19 17:09:56 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:60:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < solutions.size();i++)
                                   ^
input/code.cpp:80:31: error: no match for 'operator+' (operand types are 'std::vector<unsigned char>' and 'int')
   std::cout << reversed_steps + 1 << '\n';
                               ^
input/code.cpp:80:31: note: candidates are:
In file included from /usr/include/c++/4.8/vector:65:0,
                 from input/code.cpp:2:
/usr/include/c++/4.8/bits/stl_bvector.h:379:3: note: std::_Bit_const_iterator std::operator+(std::ptrdiff_t, const std::_Bit_const_iterator&)
   operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
   ^
/usr/include/c++/4.8/bits/stl_bvector.h:379:3: note:   no known conversion for argument 1 from 'std::vector<unsigned char>' to 'std::ptrdiff_t {aka long int}'
/usr/include/c++/4.8/bits/stl_bvector.h:293:3: note: std::_Bit_iterator std:...

Code

#include <iostream>
#include <vector>
#include <algorithm>


int min_level = 0x00FFFFFF;

struct btree
{
	btree* parent;
	btree* right;
	btree* left;
	int rl;
	int level;
	int value;
};

btree* start_node;
std::vector<btree*> solutions;
std::vector<unsigned char> reversed_steps;

void build_steps(btree* node,int req)
{
	if(node->value == req)
	{
		solutions.push_back(node);
		min_level = node->level;
		return;
	}
	if(node->value > req || node->level >= min_level)
		return;
	node->right = new btree;
	node->left = new btree;
	node->right->value = node->value * 2;
	node->right->rl = 1;
	node->left->rl = 0;
	node->left->value = node->value + 3;
	node->right->level = node->left->level = node->level + 1;
	node->right->parent = node->left->parent = node;
	build_steps(node->right,req);
	build_steps(node->left,req);
}


int main()
{
	int n;
	std::cin >> n;
	/*if(n % 3 == 0)
	{
		std::cout << '0';
		return 0;
	}*/
	start_node = new btree;
	start_node->value = 1;
	start_node->level = 0;
	build_steps(start_node,n);
	btree* quickest = (btree*)NULL;
	int quickest_steps = 0x00FFFFFFF;
	for(int i = 0;i < solutions.size();i++)
	{
		if(solutions[i]->level < quickest_steps)
		{
			quickest = solutions[i];
			quickest_steps = solutions[i]->level;
		}
	}
	if(quickest != NULL)
		reversed_steps.push_back(2); 
	btree* next = quickest;
	while(next != start_node && next != NULL)
	{
		if(next->rl == 1)
			reversed_steps.push_back(1);
		else
			reversed_steps.push_back(0);
		next = next->parent;
	}
	if(solutions.size() != 0)
		std::cout << reversed_steps + 1 << '\n';
	for(int i = reversed_steps.size()-1;i >= 0;i--)
	{
		if(reversed_steps[i] == 0)
			std::cout << "ADD\n";
		else if(reversed_steps[i] == 1)
			std::cout << "MUL\n";
		else
			std::cout << "END\n";
	}
	if(solutions.size() == 0)
		std::cout << '0';
	return 0;
}