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

int d, r;

int maxDim(int from[], int to[]){
	int mx = -1;
	int mxPos = 0;
	
	for(int i=0; i<d; i++){
		if(to[i] - from[i] > mx){
			mx = to[i] - from[i];
			mxPos = i;
		}
	}
	
	return mxPos;
}

int main(){
	d = podajD();
	r = podajR();
	
	int dimsFrom[d], dimsTo[d], q1[d], q2[d];
	
	for(int i=0; i<d; i++){
		dimsFrom[i] = 0;
		dimsTo[i] = r;
	}
	
	while(true){
		int pos = maxDim(dimsFrom, dimsTo);
		int range = dimsTo[pos] - dimsFrom[pos] + 1;
		
		if(range == 1)
			break;
		
		for(int i=0; i<d; i++)
			q1[i] = q2[i] = (dimsFrom[i] + dimsTo[i]) / 2;
		
		q1[pos] = dimsFrom[pos];
		q2[pos] = dimsTo[pos];
		
		czyCieplo(q1);
		int ans1 = czyCieplo(q2);
		int ans2 = 0;
		
		if(range == 3)
			ans2 = czyCieplo(q1);
		
		int sum = dimsFrom[pos] + dimsTo[pos];
		
		if(range == 3){
			if(ans1 != 0)
				dimsFrom[pos] += 2; 
			else if(ans2 != 0)
				dimsTo[pos] -= 2;
			else{
				dimsFrom[pos]++;
				dimsTo[pos]--;
			}				
		}else{
			if(ans1 != 0)
				dimsFrom[pos] = sum / 2;
			else
				dimsTo[pos] = sum / 2 + (sum % 2 == 1 ? 1 : 0);		
		}
	}
	
	znalazlem(dimsFrom);
	return 0;
}