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
#include "bits/stdc++.h"
#include "cielib.h"
using namespace std;

const int D = 500;

const int d = podajD();
const int r = podajR();

bool flip[D];


// (2 * d) x czyCieplo()
void reduceToNonZeroCoordinates(){
	vector<int> t(d, 1);
  for(int i = 0; i < d; ++i) {
    t[i] = r;
    czyCieplo(t.data());
    t[i] = r - 1;
    flip[i] = (czyCieplo(t.data()) == 1);
    t[i] = 1;
  }
}

vector<int> flipped(int* t){
	vector<int> tf(t, t + d);
	for(int i = 0; i < d; ++i){
		if(flip[i]) tf[i] = r - tf[i];
	}
	return tf;
}

int reducedCzyCieplo(int* t) {
	return czyCieplo(flipped(t).data());
}

void reducedZnalazlem(int* t) {
	znalazlem(flipped(t).data());
}

int main() {
  reduceToNonZeroCoordinates();
  vector<int> t(d, 0), tt(d);
  unordered_set<int> poll;
  for(int i = 0; i < d; ++i) {
  	poll.insert(i);
  }
  for(int i = 0; i < d; ++i) {
  	{
      int lo = 0; 
      int hi = poll.size();
      while(hi - lo > 1){
      	int mi = (lo + hi) / 2;
      	tt = t;
      	for(int j = 0; j < d; ++j) {
      		if(poll.count(j) == 0) ++tt[j];
      	}
      	auto it = poll.begin();
      	for(int k = 0; k < mi; k++) {
      		++tt[*it];
      		++it;
      	}
      	reducedCzyCieplo(t.data());
      	if(reducedCzyCieplo(tt.data()) == 1) {
      		hi = mi;
      	} else {
      		lo = mi;
      	}
    	}
      auto jt = poll.begin();
      advance(jt, lo);
      poll.erase(jt);
    }
    {
    	tt = t;
    		for(int j = 0; j < d; ++j) {
    			if(poll.count(j) == 0) ++tt[j];
    		}
    		reducedCzyCieplo(t.data());
    		if(reducedCzyCieplo(tt.data()) == 0) {
    			continue;
    		}
    }
    {
    	int lo = 0;
    	int hi = r - *max_element(t.begin(), t.end());
    	while(hi - lo > 1) {
    		int mi = (lo + hi) / 2;
    		tt = t;
    		for(int j = 0; j < d; ++j) {
    			if(poll.count(j) == 0) tt[j] += mi;
    		}
    		reducedCzyCieplo(tt.data());
    		for(int j = 0; j < d; ++j) {
    			if(poll.count(j) == 0) ++tt[j];
    		}
    		if(reducedCzyCieplo(tt.data()) == 1) {
    			lo = mi;
    		} else {
    			hi = mi;
    		}
    	}
    	for(int j = 0; j < d; ++j) {
    		if(poll.count(j) == 0) t[j] += hi;
    	}
    }
  }
  reducedZnalazlem(t.data());
  return 0;
}