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

int main() {
	int d = podajD();
	int r = podajR();
	int i;

	int *L = calloc(d, sizeof(*L));
	int *R = calloc(d, sizeof(*R));
	int *T = calloc(d, sizeof(*T));

	for (i=0; i<d; i++) {
		L[i] = 0;
		R[i] = r;
	}

	int cont = 1;
	while (cont) {
		for (i = 0; i < d; i++) {
			if (R[i] - L[i] == 1) {
				if (L[i] > 0) {
					L[i]--;
				} else {
					R[i]++;
				}
			}

			T[i] = (L[i] + R[i]) / 2;
		}

		cont = 0;
		for (i = 0; i < d; i++) {
			int t = T[i];
			int m1 = (L[i] + R[i]) / 2; // L, R <0; 2> => mid = 1
			int m2 = m1 + (L[i] + R[i]) % 2;
			T[i] = L[i];
			czyCieplo(T);
			T[i] = R[i];
			int v = czyCieplo(T);
			if (R[i] - L[i] == 2) {
				T[i] = L[i];
				L[i] = R[i] = v ? R[i] : czyCieplo(T) ? L[i] : m1;
			} else if (v) {
				L[i] = m1;
				R[i] = R[i];
				cont = 1;
			} else {
				L[i] = L[i];
				R[i] = m2;
				cont = 1;
			}

			T[i] = t;
		}
	}

	for (i = 0; i < d; i++) {
		T[i] = L[i];
	}

	znalazlem(T);

	return 0;
}