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 "cielib.h"

int d,k,r;

int ask(int pozycja[]) {
    k--;
    //printf("ask: %d %d\n", pozycja[0], pozycja[1]);
    return czyCieplo(pozycja);
}

int main() {
	d = podajD();
	k = podajK();
    r = podajR();

    int l[d];
    int u[d];
    int query[d];
    
    for (int i=0; i<d; i++){
        l[i] = 0;
        u[i] = r; 
    }

    int it = 0; 
    int skipped = 0;

    while (true){ 
        if (skipped >= d)
            break;
        if (u[it] == l[it]) {
            skipped++;
            it++;
            continue;
        }
        skipped = 0;
/*
        for (int i=0; i<d; i++){
            printf("%d %d %d", i, l[i], u[i]);
            if (i==it) printf("*");
          printf("\n"); 
        }
        printf("\n\n");
 */
        for (int i=0; i<d; i++){
            query[i] = (l[i] + u[i])/2;
        }

        if (u[it] - l[it] > 2) {
            query[it] = l[it];
            ask(query);

            query[it] = u[it];
            int r = ask(query);

            if (r) {
                l[it] = (l[it] + u[it] )/2; 
            } else {
                u[it] = (l[it] + u[it] +1)/2;
            }
 
        }
        else {
            if (u[it] - 1 == l[it]){
                if (l[it] != 0)
                    l[it]--;
                else
                    u[it]++;
            }

            query[it] = l[it];
            ask(query);
            query[it] = u[it];
            
            int r = ask(query);
            if (r) {
                l[it] = u[it];
            } else {
                query[it] = l[it];
                r = ask(query);
                if (r)
                    u[it] = l[it];
                else
                    u[it] = l[it] = (u[it] + l[it])/2;
            }
        }

        it = (it + 1)%d;

    }

	znalazlem(l);
}