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
#include "cielib.h"

const int d = podajD();
const int k = podajK();
const int r = podajR();
int* l = new int[d];
int* p = new int[d];

bool is_close() {
	for (int i = 0; i < d; ++i) {
		if (p[i] - l[i] > 1)
			return false;
	}
	return true;
}

void find_solution(int *pos) {
	int tmp;
	for (int i = 0; i < d; ++i) {
		l[i] = 0;
		p[i] = r;
	}
	while (!is_close()) {
		for (int i = 0; i < d; ++i) {
			pos[i] = (l[i] + p[i]) / 2;
		}
		for (int i = 0; i < d; ++i) {
			if (p[i] - l[i] > 1) {
				tmp = pos[i];
				pos[i] = l[i];
				czyCieplo(pos);
				pos[i] = p[i];
				if (czyCieplo(pos)) {
					l[i] = (l[i] + p[i]) / 2;
				} else {
					p[i] = (l[i] + p[i] + 1) / 2;
				}
				pos[i] = tmp;
			}
		}
	}
	for (int i = 0; i < d; ++i) {
		if (l[i] == p[i]) {
			pos[i] = l[i];
		} else {
			if (l[i] == 0) {
				pos[i] = 2;
				czyCieplo(pos);
				pos[i] = 0;
				if (czyCieplo(pos)) {
					pos[i] = 0;
				} else {
					pos[i] = 1;
				}
			} else if (p[i] == r) {
				pos[i] = l[i] - 1;
				czyCieplo(pos);
				pos[i] = p[i];
				if (czyCieplo(pos)) {
					pos[i] = r;
				} else {
					pos[i] = r - 1;
				}
			} else {
				pos[i] = l[i] - 1;
				czyCieplo(pos);
				pos[i] = p[i] + 1;
				if (czyCieplo(pos)) {
					pos[i] = p[i];
				} else {
					pos[i] = l[i];
				}
			}
		}
	}
}

int main() {
	int position[d];
	find_solution(position);
	znalazlem(position);
	delete[] l;
	delete[] p;
	return 0;
}