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
#include <cstdio>
#include "cielib.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int mi[500], ma[500], p[500];

int main() {
	int d = podajD();
	int r = podajR();
	REP(i,d) mi[i] = 0;
	REP(i,d) ma[i] = r;
	for (;;) {
		int i = 0;
		REP(j,d) if (ma[j] - mi[j] > ma[i] - mi[i]) i = j;
		if (ma[i] == mi[i]) znalazlem(mi);
		REP(j,d) p[j] = (mi[j] + ma[j]) >> 1;
		if (ma[i] - mi[i] == 2) {
			p[i] = mi[i];
			czyCieplo(p);
			p[i] = ma[i];
			bool c1 = czyCieplo(p);
			p[i] = mi[i];
			bool c2 = czyCieplo(p);
			if (c1) mi[i] = ma[i];
			else if (c2) ma[i] = mi[i];
			else mi[i] = ma[i] = mi[i] + 1;
		} else {
			p[i] = mi[i];
			czyCieplo(p);
			p[i] = ma[i];
			bool c = czyCieplo(p);
			int w = (ma[i] - mi[i] + 1) >> 1;
			if (c) mi[i] = ma[i] - w;
			else ma[i] = mi[i] + w;
		}
	}
}