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
#include <cstdio>
#include "cielib.h"

#define MAXD 509

using namespace std;

int query[MAXD];

struct Query {
  int left, right;
  bool upper, lower;

  int getValue() {
    return upper ? right : (lower ? left : middle(0));
  }

  void setCenter() {
    left = right = middle(0);
  }

  bool isCenter() {
    return left == right;
  }

  bool isEven() {
    return (right - left) % 2 == 1;
  }

  int middle(int change) {
    return  (left + right + change) / 2;
  }

  void checkSize(bool b) {
    if (right - left == 1) {
      b ? right++ : left--;
    }
  }
};

Query poz[MAXD];
int size[MAXD];

void makeQuery(int d) {
  for (int i=0; i<d; i++) {
    query[i] = poz[i].getValue();
  }
}

bool sendQuery(int d) {
  makeQuery(d);
 
  return czyCieplo(query);
}

bool queryFor(int d, int i, bool upper) {
  poz[i].upper = upper;
  poz[i].lower = !upper;

  bool ret = sendQuery(d);

  poz[i].upper = poz[i].lower = false;

  return ret;
}

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

  for (int i=0; i < d; i++) {
    poz[i].left = 0; poz[i].right = r;
  }

  bool needed = true;
  
  while (needed) {
    needed = false;

    //sendQuery(d);
    
    for (int i=0; i<d; i++) {
      while (poz[i].isCenter() && i < d) i++;

      queryFor(d, i, false);
      
      bool firstResult = queryFor(d, i, true);
      
      bool secondResult = queryFor(d, i, false);
      
      if (poz[i].isEven()) {
	if (secondResult) {
	  poz[i].right = poz[i].middle(0);
	  poz[i].checkSize(true);
	} else {
	  if (firstResult) {
	    poz[i].left = poz[i].middle(1);
	    poz[i].checkSize(false);
	  } else {
	    // both false, set somewhere in the middle
	    // tu ustawiałem przedział dł 3 na śrdku
	    int s = poz[i].right - poz[i].left;
	    poz[i].left += s/4;
	    if (s == 3) s = 4; 
	    poz[i].right = poz[i].left + s/2;
	  }
	}
      } else {
	// uneven
	if (secondResult) {
	  poz[i].right = poz[i].middle(-1);
	  poz[i].checkSize(true);
	} else {
	  if (firstResult) {
	    poz[i].left = poz[i].middle(2);
	    poz[i].checkSize(false);
	  } else {
	    
	    poz[i].setCenter();
	  }
	}
      }
      if (!poz[i].isCenter()) {
	needed = true;
      }
    }
  }

  sendQuery(d);

  znalazlem(query);
}