이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 450;
vector<array<int, 3> > results;
int N;
bool cmp(array<int, 3> a, array<int, 3> b)
{
return ((a[0] + a[1]) > (b[0] + b[1]));
}
int DivideAndConquer(int l, int r, int parent_value, int parent_left, int parent_right) // index of diamond (-1 if not found)
{
if(l > r)
{
return -1;
}
int mid = (l + r) >> 1;
// cout << "l = " << l << ", r = " << r << ", mid = " << mid << "\n";
vector<int> current_reply = ask(mid);
if(current_reply[0] + current_reply[1] == 0)
{
return mid;
}
if(parent_left + parent_right != current_reply[0] + current_reply[1])
{
// higher to lower or vice versa, don't do anything based on parent
if(current_reply[0] != 0)
{
int value = DivideAndConquer(l, mid - 1, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
if(current_reply[1] != 0)
{
int value = DivideAndConquer(mid + 1, r, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
return -1; // value not found in both children
}
// equal value of parent and current
// if current is the left child of parent do:
// parent_left == current_left: No need to check right child
// else if current is the right child of parent do:
// parent_right == current_left: No ned to check right child
if(parent_value == r + 1) // current is the left child of parent
{
if(current_reply[0] != 0)
{
int value = DivideAndConquer(l, mid - 1, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
if(current_reply[1] != 0 && current_reply[0] != parent_left)
{
int value = DivideAndConquer(mid + 1, r, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
return -1;
}
else
{
if(current_reply[0] != 0)
{
int value = DivideAndConquer(l, mid - 1, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
if(current_reply[1] != 0 && current_reply[0] != parent_right)
{
int value = DivideAndConquer(mid + 1, r, mid, current_reply[0], current_reply[1]);
if(value != -1) // value found
{
return value;
}
}
return -1;
}
}
int find_best(int n)
{
return DivideAndConquer(0, n - 1, n, 0, 0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |