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
#include <cstdio>
#include <set>
#include "cielib.h"
#include <cassert>
using namespace std;
#define MAXD 507
int lowb[MAXD], upb[MAXD], d, r;
set<pair<int, int>> len;

int position[MAXD];
bool serve() {
  pair<int,int> top = *len.begin();
  if (-top.first <= 3)
    return false;

  len.erase(len.begin());
  int coord = top.second;

//  assert(position[coord] == (lowb[coord] + upb[coord])/2);
  position[coord] = lowb[coord];
  czyCieplo(position);
  position[coord] = upb[coord];
  if (czyCieplo(position)) {
    int l = (upb[coord] - lowb[coord] - 1)/2;
    l = std::max(l, 2);
    lowb[coord] = upb[coord] - l;
  } else {
    int l = (upb[coord] - lowb[coord] + 1)/2;
    upb[coord] = lowb[coord] + l;
  }

  len.insert(make_pair(-(upb[coord] - lowb[coord] + 1), coord));
  position[coord] = (lowb[coord] + upb[coord])/2;

  return true;
}

void last_round(int coord) {
//  assert(upb[coord] - lowb[coord] == 2);
//  assert(position[coord] == (lowb[coord] + upb[coord])/2);

  position[coord] = lowb[coord];
  czyCieplo(position);
  position[coord] = upb[coord];
  if (czyCieplo(position)) {
    lowb[coord] = upb[coord];
  } else {
    position[coord] = lowb[coord];
    if (czyCieplo(position)) {
      upb[coord] = lowb[coord];
    } else {
      upb[coord] = (lowb[coord] + upb[coord])/2;
      lowb[coord] = upb[coord];
    }
  }
  position[coord] = lowb[coord];
}

int main() {
  d = podajD();
  r = podajR();
  for(int i = 0; i < d; i++) {
    lowb[i] = 0;
    upb[i] = r;
    len.insert(make_pair(-(r+1), i));
    position[i] = (lowb[i] + upb[i])/2;
  }

  while(serve()) {}
  for(int i = 0; i < d; i++){
    last_round(i);
  }

  znalazlem(position);
}