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
#include "cielib.h"
#include <algorithm>
using std::min;
using std::max;
int main() {
	int d = podajD(), r = podajR();
	int t[d], beg[d], end[d], cnt_finished = 0, finished[d];
  for (int i=0; i<d; i++) beg[i] = finished[i] = 0, end[i] = r;
  while (cnt_finished < d) {
    int maxwidth = 0;
    for (int i=0; i<d; i++) {
      t[i] = (beg[i] + end[i]) / 2;
      maxwidth = max(maxwidth, end[i] - beg[i]);
    }
    int maxother = (maxwidth + 1) / 2;
    for (int i=0; i<d; i++) {
      if (end[i] == beg[i]) {
        if (!finished[i]) cnt_finished++, finished[i] = true;
        continue;
      }
      if (end[i] - beg[i] == 1) {
        if (beg[i] > 0) beg[i]--; else end[i]++;
      }
      t[i] = beg[i];
      czyCieplo(t);
      t[i] = end[i];
      if (czyCieplo(t)) beg[i] = (beg[i] + end[i]) / 2 + 1;
      else if (end[i] - beg[i] == 2 && maxwidth <= 2) {
        t[i] = beg[i];
        if (czyCieplo(t)) end[i] = beg[i]; else beg[i]++, end[i]--;
      } else end[i] = min(end[i], beg[i] + maxother);
      t[i] = (beg[i] + end[i]) / 2;
    }
  }
	znalazlem(beg);
  return 0;
}