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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <vector>
#include <algorithm>
#include <iostream>

#include "cielib.h"

using namespace std;

#define LOG_ENABLED false
#define INTERACTIVE false

typedef long long ll;
typedef unsigned long long ull;
#define LOG if (LOG_ENABLED) cerr

const ull INF = 1000000009ull;


struct Dimension
{
    int a, b;
    int size;
};

vector<Dimension> dimensions;
vector<int> position;
int d, k, r;


ostream& operator<<(ostream& os, const Dimension& d)
{
    os << "(" << d.a << ", " << d.b << "; " << d.size << ")";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    string sep = "";
    for (unsigned i = 0; i < v.size(); i++)
    {
        os << sep << v[i];
        sep = ", ";
    }
    os << "]";

    return os;
}


void readData()
{
    d = podajD();
    k = podajK();
    r = podajR();

    dimensions.resize(d);
    position.resize(d);

    for (auto& dimension : dimensions)
    {
        dimension.a = 0;
        dimension.b = r;
        dimension.size = r + 1;
    }

    for (auto& pos : position)
    {
        pos = r / 2;
    }
}


int findBiggestDimension()
{
    int maxPos, maxSize;

    maxPos = 0;
    maxSize = 0;
    for (int i = 0; i < d; i++)
    {
        if (dimensions[i].size > maxSize)
        {
            maxSize = dimensions[i].size;
            maxPos = i;
        }
    }

    return maxPos;
}


void sendResult()
{
    vector<int> result = vector<int>(d);
    for (int i = 0; i < d; i++)
    {
        result[i] = dimensions[i].a;
    }
    znalazlem(result.data());
}


void solveSmall()
{
    LOG << endl << "SMALL" << endl;

    int maxIdx = findBiggestDimension();

    while (dimensions[maxIdx].size > 1)
    {
        Dimension& maxDimension = dimensions[maxIdx];
        int a = maxDimension.a;
        int b = maxDimension.b;

        position[maxIdx] = a;
        czyCieplo(position.data());
        position[maxIdx] = b;
        int rightWarmer = czyCieplo(position.data());
        position[maxIdx] = a;
        int leftWarmer = czyCieplo(position.data());

        LOG << "maxIdx: " << maxIdx << ", dim: " << maxDimension;
        LOG << ", rightWarm: " << rightWarmer << ", leftWarm: " << leftWarmer;
        LOG << endl;

        if (rightWarmer)
        {
            maxDimension.a = b;
        }
        else if (leftWarmer)
        {
            maxDimension.b = a;
        }
        else
        {
            int half = (a + b) / 2;
            maxDimension.a = half;
            maxDimension.b = half;
        }

        maxDimension.size = maxDimension.b - maxDimension.a + 1;
        position[maxIdx] = (maxDimension.a + maxDimension.b) / 2;

        LOG << "dimensions: " << dimensions << endl;
        LOG << "position: " << position << endl;

        maxIdx = findBiggestDimension();
    }
}

void solve()
{
    int maxIdx = findBiggestDimension();

    while (dimensions[maxIdx].size > 3)
    {
        Dimension& maxDimension = dimensions[maxIdx];
        int a = maxDimension.a;
        int b = maxDimension.b;

        position[maxIdx] = a;
        czyCieplo(position.data());
        position[maxIdx] = b;
        int rightWarmer = czyCieplo(position.data());

        LOG << "maxIdx: " << maxIdx << ", dim: " << maxDimension;
        LOG << ", rightWarm: " << rightWarmer;
        LOG << endl;

        if (rightWarmer)
        {
            maxDimension.a = (a + b) / 2;
            if (maxDimension.b - maxDimension.a == 1)
            {
                maxDimension.a --;
            }
        }
        else
        {
            maxDimension.b = (a + b + 1) / 2;
            if (maxDimension.b - maxDimension.a == 1)
            {
                maxDimension.b ++;
            }
        }

        maxDimension.size = maxDimension.b - maxDimension.a + 1;
        position[maxIdx] = (maxDimension.a + maxDimension.b) / 2;

        LOG << "dimensions: " << dimensions << endl;
        LOG << "position: " << position << endl;

        maxIdx = findBiggestDimension();
    }

    solveSmall();
}


int main()
{
    readData();
    solve();
    sendResult();

    return 0;
}