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

using namespace std;

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define FOR(i,n) REP(i,0,(int)n-1)
#define mp make_pair
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define VI vector<int>
#define fi first
#define se second

const int INF = 1000000042;
int d,k,r;
vector<pii> inter;

int main() {
	d = podajD();
	k = podajK();
	r = podajR();
	int t[d];
	FOR(i,d) inter.pb(mp(0,r));

	while(1) {
		// FIND LARGEST DIMENSION
		int best = -1, val = -1;
		FOR(i,d) {
			//cout<<i<<": ["<<inter[i].fi<<", "<<inter[i].se<<"]\n";
			if(inter[i].se - inter[i].fi > val) {
				best = i;
				val = inter[i].se - inter[i].fi;
			}
		}
		if(inter[best].se - inter[best].fi == 0) {
			FOR(i,d) t[i] = inter[i].fi;
			znalazlem(t);
			return 0;
		}

		if(inter[best].se - inter[best].fi == 1) {
			FOR(i,d) {
				if(i==best) {
					if(inter[i].se < r) t[i] = inter[i].se + 1;
					else t[i] = inter[i].fi - 1;
				}
				else t[i] = inter[i].fi;
			}
			czyCieplo(t);
			if(inter[best].se < r) t[best] = inter[best].fi;
			else t[best] = inter[best].se;
			
			if(czyCieplo(t) == false) {
				if(inter[best].se < r) inter[best].fi = inter[best].se;
				else inter[best].se = inter[best].fi;
			}
			else {
				if(inter[best].se < r) inter[best].se = inter[best].fi;
				else inter[best].fi = inter[best].se;	
			}
			continue;
		}
		
		FOR(i,d) {
			if(i == best) t[i] = inter[i].fi;
			else t[i] = (inter[i].fi + inter[i].se) / 2;
		}
		czyCieplo(t);
		t[best] = inter[best].se;
		if(czyCieplo(t) == false) {
			inter[best].se = inter[best].se - (inter[best].se - inter[best].fi) / 2;
		}
		else {
			inter[best].fi = inter[best].se - (inter[best].se - inter[best].fi) / 2;
		}
	}
	return 0;
}