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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <bits/stdc++.h>
#include "cielib.h"

#define F first
#define S second
#define pb push_back
#define INF (1 << 30)
#define SQR(a) ((a) * (a))

using namespace std;

const int N = 1111;

namespace nmy {

int a[N];

int getD()
{
    return podajD();
}

int getK()
{
    return podajK();
}

int getR()
{
    return podajR();
}

int isCloser(const vector<int>& v)
{
    copy(v.begin(), v.end(), a);
    return czyCieplo(a);
}

void found(const vector<int>& v)
{
    copy(v.begin(), v.end(), a);
    for (auto e : v)
        cerr << e << endl;
    znalazlem(a);
}
};

namespace my {
int d, k, r;

vector<int> p, l;

void read()
{
    freopen("input.txt", "r", stdin);
    cin >> d >> k >> r;
    p.resize(d);
    for (int i = 0; i < d; i++)
        cin >> p[i];
}

void randomize(int _d = 500, int _r = 1000000000, bool print = false)
{
    d = _d;
    k = 100 * d;
    r = _r;
    p.resize(d);
    for (int i = 0; i < d; i++)
        p[i] = rand() % (r + 1);
    if (print) {
        for (auto e : p)
            cerr << e << " ";
        cerr << endl
             << endl;
    }
}

int getD()
{
    return d;
}

int getK()
{
    return k;
}

int getR()
{
    return r;
}

int getDist(const vector<int>& w, const vector<int>& v)
{
    int mx = 0;
    for (int i = 0; i < (int)w.size(); i++) {
        mx = max(mx, abs(v[i] - w[i]));
    }
    return mx;
}

int isCloser(const vector<int>& v)
{
    if (l.size() == 0) {
        l = v;
        return 0;
    }
    int ret = 0;
    if (getDist(p, v) < getDist(p, l))
        ret = 1;
    l = v;
    return ret;
}

void found(const vector<int>& v)
{
    if (v == p) {
        cerr << " OK " << endl;
    } else {
        cerr << " FUCK " << endl;
        for (int i = 0; i < d; i++)
            cerr << p[i] << " ";
        cerr << endl;
        for (int i = 0; i < d; i++)
            cerr << v[i] << " ";
    }
}
};

namespace xx = nmy;

using xx::getD;
using xx::getR;
using xx::getK;
using xx::found;
using xx::isCloser;
using my::getDist;

int d, k, r;

pair<int, int> check(int dim, vector<int>& lov, vector<int>& hiv)
{
    static vector<int> q(d);
    for (int i = 0; i < d; i++)
        q[i] = (lov[i] + hiv[i]) / 2;

    int lo = lov[dim];
    int hi = hiv[dim];
    if (lo == hi - 1)
        return { lo, hi };
    q[dim] = lo;
    isCloser(q);
    q[dim] = hi;
    bool ret1 = isCloser(q);
    q[dim] = lo;
    bool ret2 = isCloser(q);
    if (!ret1 && !ret2) {
        return { (lo + hi) / 2, (lo + hi + 1) / 2 };
    } else if (ret1) {
        return { (lo + hi + 1) / 2, hi };
    } else {
        return { lo, (lo + hi) / 2 };
    }
}

int resolve(int i, const vector<int>& lov, const vector<int>& hiv)
{
    int lo = lov[i];
    int hi = hiv[i];
    if (hi < r) {
        vector<int> q = hiv;
        q[i] = hi + 1;
        isCloser(q);
        q[i] = lo;
        bool ret = isCloser(q);
        if (ret)
            return lo;
        else
            return hi;
    } else {
        vector<int> q = lov;
        q[i] = lo - 1;
        isCloser(q);
        q[i] = hi;
        bool ret = isCloser(q);
        if (ret)
            return hi;
        else
            return lo;
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //srand(time(NULL));
    //my::randomize(2, 4, true);
    //my::read();
    //my::randomize(3, 5, true);
    //my::randomize();

    d = getD();
    k = getK();
    r = getR();

    vector<int> lo(d, 0);
    vector<int> hi(d, r);
    vector<int> nlo(d, 0);
    vector<int> nhi(d, r);

    cerr << getDist(lo, hi) << endl;

    while (getDist(lo, hi) > 1) {
        //cerr << getDist(lo, hi) << endl;
        for (int i = 0; i < d; i++) {
            tie(nlo[i], nhi[i]) = check(i, lo, hi);
        }
        lo = nlo;
        hi = nhi;
        cerr << endl
             << "STEP:" << endl;
        for (int i = 0; i < d; i++) {
            cerr << lo[i] << " " << hi[i] << endl;
        }
    }

    vector<int> ans(d, 0);
    for (int i = 0; i < d; i++) {
        ans[i] = resolve(i, lo, hi);
    }

    found(ans);

    return 0;
}