1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#include "cielib.h"
#include <vector>
#include <set>
#include <algorithm>

std::vector<int> add(const std::vector<int> &a, const std::vector<int> &b)
{
	std::vector<int> c = a;
	for (int i=0;i<c.size();++i)
		c[i] += b[i];
	return c;
}
std::vector<int> add(const std::vector<int> &a, const std::vector<int> &b, int k)
{
	std::vector<int> c = a;
	for (int i=0;i<c.size();++i)
		c[i] += b[i] * k;
	return c;
}

int main()
{
	int D = podajD();
	int R = podajR();
	int maxR = 0;
	
	std::vector<int> dir(D,0);
	std::vector<int> pos(D,0);
	
	std::set<int> dim;
	for (int i=0;i<D;++i)
		dim.insert(i);
	
	while (!dim.empty())
	{
		int dd = -1;
		
		std::set<int> dim2 = dim;
		while (!dim2.empty())
		{
			std::set<int> dim3;
			int N = dim2.size()/2;
			for (int i=0;i<N;++i)
			{
				dim3.insert(*dim2.begin());
				dim2.erase(dim2.begin());
			}
			
			auto pos2 = add(pos, dir);
			for (int d : dim2)
				pos2[d] = 1;
			czyCieplo(pos.data());
			if (czyCieplo(pos2.data()) == 1)
			{
				if (dim2.size() == 1)
				{
					dd = *dim2.begin();
					break;
				}
			}
			else
				dim2 = dim3;
		}
		
		if (dd == -1)
		{
			bool any = false;
			for (int d : dim)
			{
				czyCieplo(pos.data());
				auto pos2 = add(pos, dir, 1);
				pos2[d] += 1;
				if (czyCieplo(pos2.data()) == 1)
				{
					dir[d] = 1;
					any = true;
				}
			}
			if (!any)
				dir = std::vector<int>(D,1);
			dim.clear();
		}
		else
		{
			dim.erase(dd);
			dir[dd] = 1;			
		}
		
		int l = 0;
		int r = R-maxR;
		
		while (l<r)
		{
			int s = (l+r)/2;
			auto pos2 = add(pos, dir, s);
			auto pos3 = add(pos2, dir);
			czyCieplo(pos2.data());
			if (czyCieplo(pos3.data()) == 1)
				l = s+1;
			else
				r = s;
		}
		
		pos = add(pos, dir, l);
		for (int d=0;d<D;++d)
			maxR = std::max(maxR, pos[d]);
	}

	znalazlem(pos.data());
}