답안 #61776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61776 2018-07-26T16:21:52 Z zadrga 커다란 상품 (IOI17_prize) C++14
0 / 100
18 ms 14516 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1 << 30)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 201111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

bool used[maxn];
vector<int> v[maxn];
set<pii> s[maxn];
int ans;

pii ASK(int x){
	if(!used[x]){
		v[x] = ask(x);
		used[x] = 1;
	}
	return mp(v[x][0], v[x][1]);
}

void solve(int l, int d){
	if(ans != -1 || l > d)
		return;

	int mid = (l + d) / 2;
	pii cur = ASK(mid);
	int sum = cur.fi + cur.se;
	if(sum == 0){
		ans = mid;
		return;
	}

	auto it = s[sum].lower_bound(cur);

	bool left = 1, right = 1;
	if(it != s[sum].begin()){
		it--;
		if(abs(cur.se - it -> se) == 0)
			left = 0;
		it++;
	}

	if(it != s[sum].end()){
		if(abs(cur.se - it -> se) == 0)
			right = 0;
	}

	s[sum].insert(cur);
	if(left)
		solve(l, mid - 1);

	if(right)
		solve(mid + 1, d);
}

int find_best(int n){
	ans = -1;
	solve(0, n - 1);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 14456 KB Integer -1 violates the range [0, 199999]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 14516 KB Integer -1 violates the range [0, 199999]
2 Halted 0 ms 0 KB -