# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
813547 | kostka | Fountain (eJOI20_fountain) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}