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
#include "cielib.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);
#define inf 1000000007
#define INF 1000000000000000000LL
#define mod 1000000007
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

set < PII > s;
VPI g;

int main() 
{

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

	int t[d];

	for(int i = 0; i < d; ++i) 
	{
		t[i] = r/2;
		s.insert(mp(r+1,i));
		g.pb(mp(0,r));
	}

	while(1) 
	{
		auto it=s.end();
		it--;

		if ( (*it).st<=1 )
			break;

		PII p=*it;

		int dlugosc=p.st;
		int ktory=p.nd;

		int a=g[ktory].st;
		int b=g[ktory].nd;

		t[ktory]=b;
		int gow=czyCieplo(t);

		t[ktory]=a;
		int pocz=czyCieplo(t);

		t[ktory]=b;
		int kon=czyCieplo(t);

		if ( pocz==0 && kon==0 )
		{
			if (dlugosc%2==0)
			{

				a=(a+b)/2;
				b=a+2;

				g[ktory].st=a;
				g[ktory].nd=b;

				t[ktory]=a+1;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));

			}
			else if (dlugosc%2==1)
			{

				t[ktory]=(a+b+1)/2;

				int x=(a+b+1)/2;

				a=x;
				b=x;

				g[ktory].st=a;
				g[ktory].nd=b;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));

			}
		}
		else if ( pocz==1 && kon==0 )
		{
			if (dlugosc%2==0)
			{

				a=a;
				b=(a+b+1)/2;

				g[ktory].st=a;
				g[ktory].nd=b;

				t[ktory]=(a+b)/2;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));

			}
			else if (dlugosc%2==1)
			{
				a=a;
				b=((a+b)/2)-1;
				if (b-a==1)
					b++;

				g[ktory].st=a;
				g[ktory].nd=b;

				t[ktory]=(a+b)/2;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));
			}
		}
		else if ( pocz==0 && kon==1 )
		{
			if (dlugosc%2==0)
			{
				a=(a+b)/2;
				b=b;

				g[ktory].st=a;
				g[ktory].nd=b;

				t[ktory]=(a+b)/2;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));

			}
			else if (dlugosc%2==1)
			{
				a=((a+b)/2)+1;
				b=b;
				if (b-a==1)
					a--;

				g[ktory].st=a;
				g[ktory].nd=b;

				t[ktory]=(a+b)/2;

				s.erase(it);
				s.insert(mp(b-a+1,ktory));
			}
		}

	}

	znalazlem(t);
}