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
94
public class cie {
	static class Interval {
		int beg;
		int end;
		public Interval (int beg, int end) {
			this.beg = beg;
			this.end = end;
		}	
		@Override
		public String toString() {
			return "(" + beg + ", " + end + ")";
		}
	}
	
	public static void main(String[] args) {
		int d = cielib.podajD();
		int r = cielib.podajR();
		
		int [] position = new int [d];
		int [] finalPosition = new int[d];
		for (int i = 0; i < d; i++) {
			finalPosition[i] = -1;
		}
		Interval [] intervals = new Interval [d];
		int intervalLength = r + 1;
		for (int i = 0; i < d; i++) {
			intervals[i] = new Interval(0, r);
		}
				
		while (intervalLength > 2) {
			for (int i = 0; i < d; i++) {
				for (int j = 0; j < d; j++) {
					if (i == j) {
						position[j] = intervals[j].beg;
					} else {
						position[j] = (intervals[j].beg + intervals[j].end) / 2;
					}
				}
				//System.out.println(Arrays.toString(intervals) + ", " + intervalLength);
				cielib.czyCieplo(position);
				position[i] = intervals[i].end;
				if (cielib.czyCieplo(position) == 1) {
					if (intervalLength % 2 == 0) {
						intervals[i].beg = intervals[i].beg + intervalLength / 2 - 1;
					} else {
						intervals[i].beg = intervals[i].beg + intervalLength / 2;
					}
				} else {
					if (intervalLength % 2 == 0) {
						intervals[i].end = intervals[i].end - intervalLength / 2 + 1;
					} else {
						intervals[i].end = intervals[i].end - intervalLength / 2;
					}
				}
			}
			intervalLength = intervals[0].end - intervals[0].beg + 1;
			//System.out.println("length: " + intervalLength);
		}
		//System.out.println(Arrays.toString(intervals));
		for (int i = 0; i < d; i++) {
			for (int j = 0; j < d; j++) {
				if (i == j) {
					if (intervals[j].beg == 0) {
						position[j] = intervals[j].end + 1;
					} else {
						position[j] = intervals[j].beg - 1;
					}
				} else {
					position[j] = intervals[j].beg;
				}
			}
			cielib.czyCieplo(position);
			if (intervals[i].beg == 0) {
				position[i] = intervals[i].beg;
				if (cielib.czyCieplo(position) == 1) {
					finalPosition[i] = position[i];
				} else {
					finalPosition[i] = position[i] + 1;
				}
			} else {
				position[i] = intervals[i].end;
				if (cielib.czyCieplo(position) == 1) {
					finalPosition[i] = position[i];
				} else {
					finalPosition[i] = position[i] - 1;
				}
			}			
		}
		//System.out.println(Arrays.toString(finalPosition));
		cielib.znalazlem(finalPosition);

	}

}