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
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include "cielib.h"

using namespace std;

int dc[501];
int dr[501];
int piv[501];

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

	for (int i = 0; i < d; ++i)
	{
		dc[i] = 0;
		dr[i] = r;
	}

	while (true)
	{
		// czy mamy rozwiazanie?
		bool end = true;
		int o = 0;
		while (end && (o < d)) end &= dr[o++] == 0;		
		if (end) break;
		
		//
		for (int j = 0; j < d; ++j)
		{
			piv[j] = dc[j] + dr[j] / 2;
		}
		//
		
		for (int i = 0; i < d; ++i)
		{
			if (i > 0)
			{
				piv[i-1] = dc[i-1] + dr[i-1] / 2;
			}

			if (dr[i] == 0) continue;

			// rob nieparzyste jak sie da
			if ((dr[i]) % 2 == 1)
			{
				if (dc[i] > 0)
				{
					dc[i]--;
					dr[i]++;
				}
				else
				{
					if ((dc[i] + dr[i]) < r)
					{
						dr[i]++;
					}
				}
			}

			int zapas = min(dc[i], r-dc[i]-dr[i]);			
			int mindc = dc[i] - zapas;
			int maxdc = dc[i] + dr[i] + zapas;	

			piv[i] = mindc;
			czyCieplo(piv);
			piv[i] = maxdc;

			if (czyCieplo(piv) == 1)
			{
				dc[i] = dc[i] + dr[i] / 2 + 1;
				dr[i] = (dr[i] - 1) / 2;				
				continue;
			}
			piv[i] = mindc;
			if (czyCieplo(piv) == 1)
			{
				dc[i] = dc[i];
				dr[i] = (dr[i] - 1) / 2 ;
				continue;
			}

			if ((maxdc-mindc) % 2 == 0)
			{
				dc[i] = dc[i] + dr[i] / 2;
				dr[i] = 0;				
			}
		}
		
	}

	znalazlem(dc);

	return 0;
}