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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#define ST first
#define ND second
#define MP make_pair

#include "cielib.h"
#include <algorithm>

using namespace std;

const int MAX_D = 507;
int position[MAX_D];
pair <int, int> range[MAX_D];
bool found[MAX_D];
int notFound;

bool evenRange(pair<int, int> p) {
    return (p.ND - p.ST + 1) % 2 == 0;
}

int middle(pair<int, int> p) {
    return p.ST + ((p.ND - p.ST) / 2);
}

void updateRange(int d) {
    int mid = position[d];
    int size = range[d].ND - range[d].ST + 1;
    bool even = evenRange(range[d]);

    position[d] = range[d].ND;
    czyCieplo(position);
    position[d] = range[d].ST;

    if (size == 3) {
        if (czyCieplo(position)) {
            position[d] = range[d].ST;
            found[d] = true;
            --notFound;
            return;
        }
        position[d] = range[d].ND;
        if (czyCieplo(position)) {
            position[d] = range[d].ND;
        } else {
            position[d] = mid;
        }
        found[d] = true;
        --notFound;
        return;
    }

    if (size == 4 || size == 5) {
        if (czyCieplo(position)) {
            range[d].ND = range[d].ST + 2;
        } else {
            range[d].ST = range[d].ND - 2;
        }
        position[d] = middle(range[d]);
        return;
    }

    if (size == 6) {
        if (czyCieplo(position)) {
            range[d].ND = range[d].ST + 3;
        } else {
            range[d].ST = range[d].ND - 3;
        }
        position[d] = middle(range[d]);
        return;
    }

    if (even) {
        if (czyCieplo(position)) {
            range[d].ND = mid + 1;
        } else {
            range[d].ST = mid;
        }
        position[d] = middle(range[d]);
        return;
    } else {
        if (czyCieplo(position)) {
            range[d].ND = mid - 1;
            position[d] = middle(range[d]);
            return;
        }
        position[d] = range[d].ND;
        if (czyCieplo(position)) {
            range[d].ST = mid + 1;
            position[d] = middle(range[d]);
        } else {
            position[d] = mid;
            found[d] = true;
            --notFound;
        }
    }
}

void initRanges(int d, int r) {
    for (int i = 0; i < d; ++i) {
        range[i] = MP(0, r);
        position[i] = middle(range[i]);
    }

    czyCieplo(position);
}

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

    initRanges(d, r);

    while (notFound > 0) {
        for (int i = 0; i < d; ++i) {
            if (!found[i]) {
                updateRange(i);
            }
        }
    }

    znalazlem(position);
}