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
#include<algorithm>
#include<cassert>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<vector>

#include "cielib.h"

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#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)

typedef pair<VI, VI> SQ;

bool improve(SQ& square) {
    int d = square.first.size();
    int r = square.second[0] - square.first[0];
    if (r == 1) return false;
    if (r == 2) {
        exit(1);
    }
    
    int* guess = new int[d];
    REP(i, d) guess[i] = (square.first[i] + square.second[i]) / 2;
    if (r == 3) {
        REP(i, d) {
            guess[i] = square.first[i];
            czyCieplo(guess);
            guess[i] = square.second[i] - 1;
            bool up = czyCieplo(guess);
            guess[i] = square.first[i];
            bool down = czyCieplo(guess);
            if (up) {
                square.first[i] += 2;
            } else if (down) {
                square.second[i] -= 2;
            } else {
                square.first[i] += 1;
                square.second[i] -= 1;
            }
            guess[i] = (square.first[i] + square.second[i]) / 2;
        }
    } else {
        REP(i, d) {
            guess[i] = square.first[i];
            czyCieplo(guess);
            guess[i] = square.second[i] - 1;
            if (czyCieplo(guess)) {
                square.first[i] += (r - 1) / 2;
            } else {
                square.second[i] -= (r - 1) / 2;
            }
            guess[i] = (square.first[i] + square.second[i]) / 2;
        }
    }
    delete[] guess;
    return true; 
}

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

    SQ square(VI(d, 0), VI(d, r));
    while (improve(square)) {}

    int* solution = new int[d];
    REP(i, d) solution[i] = square.first[i];
    znalazlem(solution);
    delete[] solution;

    return 0;
}