답안 #61768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61768 2018-07-26T15:57:13 Z zadrga 커다란 상품 (IOI17_prize) C++14
0 / 100
16 ms 5120 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
#define SQRT 450
#define BUCKET 5000

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

int max_val;
int ans;
bool used[maxn];
vector<int> v[maxn];

vector<int> ASK(int x){
	if(!used[x]){
		v[x] = ask(x);
		used[x] = 1;
	}
	return v[x];
}

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

	int l = -1, d = -1;
	vector<int> left, right;
	for(int i = L; i <= D; i++){
		left = ASK(i);

		if(left[0] + left[1] == 0){
			ans = i;
			return;
		}

		if(left[0] + left[1] == max_val){
			l = i;
			break;
		}
	}

	if(l == -1)
		return;

	for(int i = D; i > l; i--){
		right = ASK(i);

		if(right[0] + right[1] == 0){
			ans = i;
			return;
		}

		if(right[0] + right[1] == max_val){
			d = i;
			break;
		}
	}
	if(d == -1)
		return;

	int num = left[1] - right[1];
	if(num == 0)
		return;

	int mid = (l + d) / 2;
	solve(l + 1, mid);
	solve(mid + 1, d - 1);
}

int find_best(int n){
	max_val = -1;
	for(int i = 0; i < min(SQRT + 50, n); i++){
		vector<int> ret = ASK(i);
		max_val = max(max_val, ret[0] + ret[1]);
	}

	solve(0, n - 1);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 5112 KB answer is not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 5120 KB answer is not correct
2 Halted 0 ms 0 KB -