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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <cstdlib>
#include <vector>
#include "cielib.h"
#include <cstring>

#define MAXD 501

int r,d,k;
int low_range[MAXD], hi_range[MAXD], querry[MAXD];

inline void read_data()
{
  d = podajD();
  k = podajK();
  r = podajR();
}

inline void set_querry( int start, int stop )
{
  for (int i = 0; i < d; ++i)
    querry[i] = low_range[i];
  for (int i = start; i <= stop; ++i)
    querry[i] = hi_range[i];
}

int get_max_diff()
{
  czyCieplo(low_range);
  int hi_dim = d-1, lo_dim = 0, mid = (hi_dim + lo_dim)/2, res = 0;
  set_querry(mid+1, hi_dim);
  res = czyCieplo(querry);
  if (res == 0)
  {
    czyCieplo(low_range);
    set_querry(lo_dim, mid);
    if (czyCieplo(querry) > 0)
      hi_dim = mid;
    else    // wverything is below upper bounds
      return -1;
  }
  else
    lo_dim = mid+1;
  while (hi_dim > lo_dim)
  {
    czyCieplo(low_range);
    mid = (hi_dim + lo_dim)/2;
    set_querry(mid+1,hi_dim);
    res = czyCieplo(querry);
    if ( res == 1 )
      lo_dim = mid+1;
    else
      hi_dim = mid;
  }
  return lo_dim;
}


inline void set_querry2( int start, int stop )
{
  for (int i = 0; i < d; ++i)
    querry[i] = hi_range[i];
  for (int i = start; i <= stop; ++i)
    querry[i] = low_range[i];
}

int get_max_diff2()
{
  czyCieplo(hi_range);
  int hi_dim = d-1, lo_dim = 0, mid = (hi_dim + lo_dim)/2, res = 0;
  set_querry2(mid+1, hi_dim);
  res = czyCieplo(querry);
  if (res == 0)
  {
    czyCieplo(hi_range);
    set_querry2(lo_dim, mid);
    if (czyCieplo(querry) > 0)
      hi_dim = mid;
    else    // wverything is below upper bounds
      return -1;
  }
  else
    lo_dim = mid+1;
  while (hi_dim > lo_dim)
  {
    czyCieplo(hi_range);
    mid = (hi_dim + lo_dim)/2;
    set_querry2(mid+1,hi_dim);
    res = czyCieplo(querry);
    if ( res == 1 )
      lo_dim = mid+1;
    else
      hi_dim = mid;
  }
  return lo_dim;
}





bool all_eq()
{
  for (int i = 0; i < d; ++i)
    if (low_range[i] < hi_range[i]) return false;
  return true;
}

void solve()
{
  memset(low_range, 0, sizeof(low_range));
  for (int i = 0; i < MAXD; ++i)
    hi_range[i] = r;
  while (! all_eq())
  {
    // get min diff returns negative value if every point is in lower half
    int position = get_max_diff();
    if (position >= 0)
      low_range[position] = (low_range[position] + hi_range[position])/2 + 1;
    else
    {
      position = get_max_diff2();
      hi_range[position] = (low_range[position] + hi_range[position])/2;
    }
  }
}


inline void output()
{
  znalazlem(low_range);
}

int main() {
  read_data();
  solve();
  output();
}