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
#include <iostream>
#include <vector>
#include "cielib.h"

using namespace std;

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

	int size = r;
	vector<int> p(d);
	
	while (size > 2)
	{
		vector<int> p2(d);
		
		for (int i = 0; i < d; i++)
		{
			vector<int> q1(d);
			vector<int> q2(d);
			for (int j = 0; j < d; j++)
				if (j == i)
				{
					q1[j] = p[j];
					q2[j] = p[j] + size;
				}
				else
				{
					q1[j] = p[j] + size/2;
					q2[j] = p[j] + (size+1)/2;
				}

			czyCieplo(&q1[0]);
			if (czyCieplo(&q2[0]))
				p2[i] = p[i] + size/2;
			else
				p2[i] = p[i];
		}
		
		size = (size+1) / 2;
		p.swap(p2);
	}
	
	vector<int> z(d);

	for (int i = 0; i < d; i++)
	{
		vector<int> q1(d);
		vector<int> q2(d);

		for (int j = 0; j < d; j++)
			if (j == i)
			{
				q1[j] = p[j];
				q2[j] = p[j] + 2;
			}
			else
			{
				q1[j] = p[j] + 1;
				q2[j] = p[j] + 1;
			}

		czyCieplo(&q1[0]);
		if (czyCieplo(&q2[0]))
			z[i] = p[i] + 2;
		else if (czyCieplo(&q1[0]))
			z[i] = p[i];
		else
			z[i] = p[i] + 1;
	}
	
	znalazlem(&z[0]);
	
	return 0;
}