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
#include <vector>
#include <iostream>
#include "cielib.h"
using namespace std;


void lookInIthDimension(vector<int>& upper, vector<int>& lower, vector<int>& middle, int& i, bool allThreeOrLess)
{
	if(lower[i] == upper[i]){
		return; // znalezione, nie ma co dalej sprawdzac
	}
	if(upper[i] - lower[i] == 2 && !allThreeOrLess) return;
	
	int middle_temp = middle[i];
	middle[i] = lower[i];
	czyCieplo(middle.data());
	middle[i] = upper[i];
	if(czyCieplo(middle.data()) == 1){
		if(upper[i] - lower[i] == 2){ lower[i] = middle[i] = upper[i]; return;}
		if((upper[i] - lower[i])%2 == 0)
		{
			lower[i] = middle_temp;
			middle[i] = (lower[i] + upper[i])/2;
		}
		else
		{
			lower[i] = middle_temp;
			middle[i] = (lower[i] + upper[i])/2;
		}
		if(upper[i] - lower[i] == 1)
			lower[i]--;
		return;
	}
	middle[i] = lower[i];
	if(czyCieplo(middle.data()) == 1){ // obszar po lewej
		if(upper[i] - lower[i] == 2){ upper[i] = middle[i] = lower[i]; return;}
        if((upper[i] - lower[i])%2 == 0)
        {
			upper[i] = middle_temp;
            middle[i] = (lower[i] + upper[i])/2;
		}
		else
		{
			upper[i] = middle_temp + 1;
			middle[i] = (lower[i] + upper[i])/2;
		}
		if(upper[i] - lower[i] == 1)
			upper[i]++;
        return;
	}
	if((upper[i] - lower[i])%2 == 0)
		lower[i] = upper[i] = middle[i] = middle_temp;
	else
	{
		lower[i] = middle_temp;
		upper[i] = middle_temp +2;
	}
}

bool checkIfFound(const vector<int>& a, const vector<int>& b)
{
	for(int i = 0 ; i < a.size(); i++)
		if(a[i]!=b[i])
			return false;
	return true;
} 

bool isThreeOrLower(const vector<int>& a, const vector<int>& b)
{
	for(int i = 0 ; i < a.size(); i++)
		if(a[i] != b[i] && a[i]-b[i] != 2)
			return false;
	return true;
}

int main()
{
	bool end = false;
	bool threeOnly = false;
	int k,d,r;
	k = podajK();
	d = podajD();
	r = podajR();
	vector<int> upper, lower, middle; upper.resize(d), lower.resize(d), middle.resize(d);
	
	for(int i = 0; i < d; i++) upper[i] = r, lower[i] = 0, middle[i] = r/2;
	
	while(!end)
	{
				for(int i = 0; i < d; i++)
			lookInIthDimension(upper, lower, middle, i, threeOnly);

		end = checkIfFound(upper, lower);
		threeOnly = isThreeOrLower(upper, lower);
	}
	znalazlem(lower.data());
	return 0;
}