답안 #1056817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056817 2024-08-13T11:33:59 Z phoenix 커다란 상품 (IOI17_prize) C++17
20 / 100
50 ms 5540 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 200200;
const int B = 256;

vector<int> arr[N];

vector<int> ASK(int p) {
	if (arr[p].empty())
		arr[p] = ask(p);
	return arr[p];	
}

int sum(int i) {
	return ASK(i)[0] + ASK(i)[1];
}

int find_best(int n) {
	int val = sum(0);
	
	for (int i = 0; i < min(n, B); i++) {
		if (!sum(i)) return i;
		val = max(val, sum(i));
	}
	int cnt = 0;
	for (int i = 0; i < B; i++) 
		cnt += (sum(i) < val);
	
	for (int it = B; it < n; it += B) {
		int rb = min(it + B - 1, n - 1), k = 0;
		
		if (sum(rb) == val && arr[rb][0] == cnt) 
			continue;

		bool skip = false;
		while (rb >= it && sum(rb) < val) {
			if (!sum(rb)) return rb;
			if (sum(rb) == 1 && !arr[rb][0])
				skip = true;
			k++;
			rb--;
		}
		if (skip) continue;

		int i = it;
		while (i < rb && cnt < arr[rb][0]) {
			while (i < rb && sum(i) < val) {
				if (!sum(i))
					return i;
				if (sum(i) == 1 && !arr[i][0])
					break;
				cnt++;
				i++;
			}
			if (cnt == arr[rb][0]) break;
			int l = i, r = rb;
			while (r - l > 1) {
				int mid = (l + r) / 2;
				if (ASK(mid) == ASK(i)) 
					l = mid;
				else {
					if (!sum(mid))
						return mid;
					r = mid;
				}
			}
			i = r;
		}
		cnt += k;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 5 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 4 ms 5140 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 4 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 4 ms 5164 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 5 ms 4952 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 5 ms 5144 KB Output is correct
11 Correct 8 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Partially correct 25 ms 5456 KB Partially correct - number of queries: 5926
14 Correct 3 ms 4952 KB Output is correct
15 Correct 9 ms 5172 KB Output is correct
16 Partially correct 47 ms 5464 KB Partially correct - number of queries: 8968
17 Correct 2 ms 4952 KB Output is correct
18 Incorrect 50 ms 5540 KB Incorrect
19 Halted 0 ms 0 KB -