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
import static java.lang.Math.max;
import static java.lang.Math.min;

import java.util.Arrays;

public class cie {
    public static void main(String[] args) {
        int d = cielib.podajD();
        int r = cielib.podajR();
        int biggest = r / 2 + 1;
        int[] t = new int[d];
        Arrays.fill(t, r / 2);
        int[] lows = new int[d];
        int[] highs = new int[d];
        boolean done = false;
        Arrays.fill(highs, r);

        while (!done) {
            done = true;
            int next = 0;
            for (int i = 0; i < d; i++)
                if (lows[i] != highs[i]) {
                    if (lows[i] + 1 == highs[i]) {
                        get(t, i, lows[i] - 1);
                        if (get(t, i, lows[i] + 1) == 1) {
                            lows[i]++;
                        } else {
                            highs[i]--;
                        }
                        t[i] = lows[i];
                    } else {
                        int mid = (highs[i] + lows[i]) >>> 1;
                        get(t, i, mid);
                        get(t, i, max(mid - biggest, 0));
                        int y = get(t, i, min(mid + biggest, r));

                        if (y == 1) {
                            lows[i] = mid;
                        } else {
                            highs[i] = mid;
                        }
                        t[i] = ((highs[i] + lows[i]) >>> 1);

                        if (lows[i] != highs[i]) done = false;
                    }
                    int dist = max(highs[i] - t[i], t[i] - lows[i]);
                    next = max(next, dist);
                }
            biggest = next + 1;
        }
        cielib.znalazlem(t);
    }

    private static int get(final int[] t, final int i, final int high) {
        t[i] = high;
        return cielib.czyCieplo(t);
    }

}