| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 813547 | kostka | Fountain (eJOI20_fountain) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#include "stub.h"
using namespace std;
int encode(int a, int b, int n) {
  return a*n+b;
}
int solve(int n) {
  set <int> diagonals_from_0;
  for (int i=1; i<n-1; i++) {
    if (query(0, i)) {
      diagonals_from_0.insert(i);
    }
  }
  // If there exist a diagonal cutting the polygon exactly in half,
  // that has to be the answer, as any other diagonal will have either
  // left or right distance greater than it (because all the remaining
  // diagonals will be either in left or right side of the polygon divided
  // with this diagonal).
  if (diagonals_from_0.find(n/2) != diagonals_from_0.end()) {
    return encode(0, n/2, n);
  }
  // Otherwise, we try to find the closest points to the opposite of 0 
  // that have a diagonal going from 0 in both left 
  // and right side of this polygon.
  int left = 1, right = n-1;
  for (int i=2; i<n/2; i++) {
    if (diagonals_from_0.find(i) != diagonals_from_0.end()) left = i;
  }
  for (int i=n-2; i>=(n+1)/2; i--) {
    if (diagonals_from_0.find(i) != diagonals_from_0.end()) right = i;
  }
  // This diagonal has to exist, as we don't have diagonal conneting 0
  // and the point opposite of 0, and it is a complete triangulation.
  // Therefore it is our answer.
  return encode(left, right, n);
}
