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
236
237
238
239
240
241
// Artur Kraska, II UWr

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <ctime>
#include <list>
#include <set>
#include <map>

#include "cielib.h"

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(typeof(coll.begin()) iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(typeof(coll.rbegin()) iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007

using namespace std;

int initialized = -1;

/************************************************************/
/*
int d_v, k_v, r_v;

int call = 0;

void init(void);

int podajD(void) {
	init();

	return d_v;
}

int podajK(void) {
	init();

	return k_v;
}

int podajR(void) {
	init();

	return r_v;
}

int pos[500];

void init(void) {
	if(initialized != -1) {
		return;
	}
	call = 0;
	initialized = 1;
	srand(time(0));

//	printf("Podaj d: ");
//	scanf("%d", &d_v);
//	printf("Podaj k: ");
//	scanf("%d", &k_v);
//	printf("Podaj r: ");
//	scanf("%d", &r_v);

    d_v = 500;
    k_v = 100*d_v;
    r_v = 1000000000;

//	printf("Podaj pozycje Krotki:\n");
	for(int i = 0; i < podajD(); ++i) {
		//scanf("%d", &pos[i]);
		pos[i] = rand()*rand()%(r_v+1);
	}
}

int czyCieplo(int answer[]) {
	init();

	call += 1;
	if(call > podajK()) {
		printf("Przekroczono limit k = %d.", k_v);
		exit(1);
	}

	static int ldiff = -1;
	int diff = 0;

	for(int d, i = 0; i < podajD(); ++i) {
		d = pos[i] - answer[i];
		d = (d<0) ? -d : d;

		diff = (d > diff) ? d : diff;
	}

	const int result = (diff < ldiff) ? 1 : 0;
	ldiff = diff;

	return result;
}

void znalazlem(int answer[]) {
	init();

//	printf("Podano:\n");
//	for(int i = 0; i < podajD(); ++i) {
//		printf("%d%c", pos[i], (i + 1 == podajD()) ? '\n' : ' ');
//	}

	int k = 1;
	for(int i = 0; i < podajD(); ++i) {
		if(answer[i] != pos[i]) {
			printf("NIE - %d na %d! Powinno byc %d\n", answer[i], i, pos[i]);
			k = -1;
		}
	}

	if(k == 1) {
		printf("OK --- %d zapytan\n", call);
	}

//	exit(0);
}

/************************************************************/

int d, k, r;
int odp[507];

struct poz
{
    int pocz, kon;
};
poz tab[507];

bool duze()
{
    forr(i, d)
        if(tab[i].kon > tab[i].pocz+1)
            return 1;
    return 0;
}

void zawezaj(int nr)
{
    forr(i, d)
        odp[i] = (tab[i].pocz + tab[i].kon)>>1;

    odp[nr] = tab[nr].pocz;
    czyCieplo(odp);
    odp[nr] = tab[nr].kon;
    bool x = czyCieplo(odp);
    if(x)
    {
        tab[nr].pocz = (tab[nr].pocz + tab[nr].kon)>>1;
    }
    else
    {
        tab[nr].kon = (tab[nr].pocz + tab[nr].kon+1)>>1;
    }
//    cout << "nr " << nr << ": [" << tab[nr].pocz << ", " << tab[nr].kon << "]" << endl;
}

void zawezaj2(int nr)
{
    forr(i, d)
        odp[i] = tab[i].pocz;

    int l = tab[nr].pocz, p = tab[nr].kon;
    if(p < r)
        p++;
    else
        l--;

    odp[nr] = l;
    czyCieplo(odp);
    odp[nr] = p;
    bool x = czyCieplo(odp);
    odp[nr] = l;
    bool y = czyCieplo(odp);
    if(x)
    {
        tab[nr].pocz = p;
    }
    else if(y)
    {
        tab[nr].pocz = l;
    }
    else
    {
        tab[nr].pocz = (l+p)>>1;
    }
}

int main() {

    forr(ttt, 1)
    {

        initialized = -1;

        d = podajD();
        k = podajK();
        r = podajR();

        forr(i, d)
        {
            tab[i].pocz = 0;
            tab[i].kon = r;
        }

        while(duze())
        {
            forr(i, d)
            {
                zawezaj(i);
            }
        }

        forr(i, d)
            zawezaj2(i);

        forr(i, d)
            odp[i] = tab[i].pocz;

        znalazlem(odp);
    }
}