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

const int MAX_D = 509;

int d, k, r;

int min[MAX_D];
int max[MAX_D];

int p[MAX_D];

void solve_max_one() {
    for (int j = 0; j < d; ++j) {
        p[j] = min[j];
    }
    czyCieplo(p);
    for (int i = 0; i < d; ++i) {
        int tmp = p[i];
        if (p[i]+2 <= r) {
            p[i] += 2;   
        } else {
            p[i] -= 1;
        }
        czyCieplo(p);
        p[i] = tmp;
        if (czyCieplo(p) != (p[i]+2 <= r)) {
            p[i] += 1;
        }
    }
}


void binsearch() {
    for (;;) {
        int m = 0;
        int a = -1;
        for (int i = 0; i < d; ++i) {
            if (max[i]-min[i] > m) {
                m = max[i]-min[i];
                a = i;
            }
        }
        if (m == 1) {
            break;
        }
        for (int j = 0; j < d; ++j) {
            p[j] = (min[j]+max[j])/2;
        }
        p[a] = min[a];
        czyCieplo(p);
        p[a] = max[a];
        if (czyCieplo(p)) {
            min[a] = (min[a]+max[a])/2;
        } else {
            max[a] = (min[a]+max[a]+1)/2;
        }
    }
}

int main() {
    d = podajD();
    k = podajK();
    r = podajR();
    for (int i = 0; i < d; ++i) {
        max[i] = r;
    }
    binsearch();
    solve_max_one();
    znalazlem(p);
}