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
#include "cielib.h"
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
#define FOR(i, n) for(int i = 0; i < n; i++)

const int MAX_D = 510;

struct Interval {
	int beg, end;

	Interval(){}
	Interval(int beg, int end): beg(beg), end(end) {}

	int f() {
		return end - beg;
	}
	int mean() {
		return (beg + end) / 2;
	}

	void update_beg() {
		beg = mean() + 1;
	}

	void update_end() {
		end = mean() + (f() & 1);
	}
};

int r, d, k;

Interval I[MAX_D];
int *inp[2];


int procceed() {
	int max_d = -1, max_f = 1;
	for(int i = 0; i < d; i ++) {
		int f = I[i].f();
		if(f > max_f) {
			max_f = f;
			max_d = i;
		}
		inp[0][i] = I[i].mean();
		inp[1][i] = I[i].mean();
	}

	if(max_d == -1) return max_d;

	inp[0][max_d] = I[max_d].beg;
	inp[1][max_d] = I[max_d].end;

	return max_d;
}

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

	inp[0] = new int[d];
	inp[1] = new int[d];

	for(int i = 0; i < d; i++)
		I[i] = Interval(0, r);

	int d_idx, status;
	while((d_idx = procceed()) != -1) {
		czyCieplo(inp[0]);
		status = czyCieplo(inp[1]);

		switch(status) {
			case 0:
				I[d_idx].update_end();
				break;
			case 1:
				I[d_idx].update_beg();
		}
	}

	// case when every length == 1
	for(int i = 0; i < d; i++) {
		inp[0][i] = I[i].beg;
		inp[1][i] = I[i].beg;
	}

	for(int i = 0; i < d; i++) {
		switch(I[i].beg) {
			case 0:
				inp[0][i] = I[i].end + 1;
				czyCieplo(inp[0]);
				status = czyCieplo(inp[1]);
				if(status == 0) 
					FOR(t, 2) inp[t][i] = I[i].end;
				if(status == 1)
					FOR(t, 2) inp[t][i] = I[i].beg;
				break;
			default:
				inp[0][i] = I[i].beg - 1;
				inp[1][i] = I[i].end;
				czyCieplo(inp[0]);
				status = czyCieplo(inp[1]);
				if(status == 0)
					FOR(t, 2) inp[t][i] = I[i].beg;
				if(status == 1)
					FOR(t, 2) inp[t][i] = I[i].end;

		}
	}
	
	znalazlem(inp[0]);

	delete inp[0];
	delete inp[1];
}