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
#include "cielib.h"
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define REP(i,n) for(int i=0;i<(n);++i)
#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 foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define scanf(...) scanf(__VA_ARGS__)?:0
#define e1 first
#define e2 second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int r,d,k,mins,maks,debug,pos[500],u[500],pom[500];
int main()
{
	r=maks=podajR();
	d=podajD();
	k=podajK();
	REP(i,d) pos[i]=r/2;
	if (d==1)
	{
		u[0]=1;
		pos[0]=0;
		mins=0;
		maks=r;
		goto szukaj;
	}
	REP(i,d)
	{
		int mins=0,maxs=r;
		pos[i]=0; 
		czyCieplo(pos);
		pos[i]=r;
		if (czyCieplo(pos)==1) u[i]=1;
		else u[i]=-1;
		if (u[i]==1)
		{
			while (mins<maxs)
			{
				int ts=(mins+maxs)/2;
				pos[i]=ts;
				czyCieplo(pos);
				pos[i]++;
				if (czyCieplo(pos)==0) maxs=ts;
				else mins=ts+1;
			}
			pos[i]=mins;
			if (r-pos[i]<maks) maks=r-pos[i];
		}
		else
		{
			int pier=0;
			while (mins<maxs)
			{
				int ts=(mins+maxs)/2;
				pos[i]=ts+1;
				czyCieplo(pos);
				pos[i]--;
				if (czyCieplo(pos)==0) mins=ts+1;
				else maxs=ts;
				pier++;
			}
			pos[i]=mins;
			if (pos[i]<maks) maks=pos[i];
		}
	}
	szukaj:
	debug=1;
	while (mins<maks)
	{
		int ts=(mins+maks)/2;
		REP(i,d) pom[i]=pos[i]+u[i]*ts;
		czyCieplo(pom);
		REP(i,d) pom[i]+=u[i];
		if (czyCieplo(pom)==0) maks=ts;
		else mins=ts+1;
	}
	REP(i,d) pos[i]+=u[i]*mins;
	znalazlem(pos);
}