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
#include <bits/stdc++.h>
#include "cielib.h"
using namespace std;

const int MAXD = 503;

int t[MAXD], d, k, r;
int l[MAXD], p[MAXD];

int main(){
	d = podajD();
	k = podajK();
	r = podajR();
	for (int i = 0; i < d; ++i){
		l[i] = 0, p[i] = r;
		t[i] = r / 2;
	}
	bool zwroc;
	zwroc = czyCieplo(t);
	int size = r + 1;
	while(size >= 3){
		size = 0;
		for (int i = 0; i < d; ++i){
			if (p[i] - l[i] + 1 == 1){
				size = max(size, 1);
				continue;
			}
			int sr = (p[i] + l[i]) / 2;
			t[i] = l[i];
			zwroc = czyCieplo(t);
			t[i] = p[i];
			zwroc = czyCieplo(t);
			if (zwroc == 1){
				l[i] = sr + 1;
				t[i] = (l[i] + p[i]) / 2;
				size = max(size, p[i] - l[i] + 1);
				continue;
			}
			t[i] = l[i];
			zwroc = czyCieplo(t);
			if (zwroc == 1){
				p[i] = sr;
				t[i] = (l[i] + p[i]) / 2;
				size = max(size, p[i] - l[i] + 1);
				continue;
			}
			t[i] = l[i] = p[i] = sr;
			size = max(size, p[i] - l[i] + 1);
		}
	}
	bool czy = false;
	for (int i = 0; i < d; ++i){
		if (p[i] - l[i] + 1 == 2){
			if (p[i] == r){
				l[i]--;
				t[i] = p[i] - 1;
			}
			else{
				p[i]++;
				t[i] = l[i] + 1;
			}
			czy = true;
		}
	}
	if (czy == true || r == 2){
		for (int i = 0; i < d; ++i){
			if (p[i] - l[i] + 1 != 1){
				int sr = (p[i] + l[i]) / 2;
				t[i] = l[i];
				zwroc = czyCieplo(t);
				t[i] = p[i];
				zwroc = czyCieplo(t);
				if (zwroc == 1){
					t[i] = p[i];
					t[i]--;
					// if (l[i] == 0)
						// t[i] --;
					continue;
				}
				t[i] = l[i];
				if (p[i] == r)
					t[i]++;
				zwroc = czyCieplo(t);
				if (zwroc == 1){
					t[i] = l[i];
					continue;
				}
				t[i] = l[i] = p[i] = sr;
			}
		}
	}
	znalazlem(t);
}