답안 #1082920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082920 2024-09-02T05:52:06 Z happypotato 커다란 상품 (IOI17_prize) C++17
90 / 100
71 ms 3920 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
vector<pii> sto;
pii Ask(int x) {
	if (sto[x].ff != -1) return sto[x];
	vector<int> res = ask(x);
	return (sto[x] = make_pair(res[0], res[1]));
}
int brainless(int n) {
	for (int i = 0; i < n; i++) {
		pii ret = Ask(i);
		if (ret.ff + ret.ss == 0) return i;
	}
	throw runtime_error("no answer?");
}
vector<int> bit;
void update(int pos) {
	pos++;
	int n = (int)(bit.size()) - 1;
	while (pos <= n) {
		bit[pos]++;
		pos += (pos & -pos);
	}
}
int pquery(int pos) {
	int n = (int)(bit.size()) - 1;
	int res = 0;
	while (pos >= 1) {
		res += bit[pos];
		pos -= (pos & -pos);
	}
	return res;
}
int query(int l, int r) {
	if (l > r) return 0;
	l++; r++;
	return pquery(r) - pquery(l - 1);
}
int find_best(int n) {
	sto.clear(); sto.resize(n, make_pair(-1, -1));
	bit.clear(); bit.resize(n + 1, 0);
	if (n <= 5000) return brainless(n);
	// only 472 max: 1 4 21 446 []
	int times = 0;
	for (int i = 1; i <= 473; i++) {
		pii ret = Ask(i);
		times = max(times, ret.ff + ret.ss);
	}
	vector<int> v(n);
	for (int i = 0; i < n; i++) v[i] = i;

	auto findone = [&]() -> int {
		int lb = 0, rb = (int)(v.size()) - 1;
		while (lb < rb) {
			int mid = (lb + rb) >> 1;
			pii ret = Ask(v[mid]);
			if (ret.ff + ret.ss < times) return v[mid];
			if (query(0, v[mid] - 1) < ret.ff) rb = mid;
			else lb = mid + 1;
		}
		return v[lb];
	};

	for (int t = 1; t <= times; t++) {
		int res = findone();
		pii ret = Ask(res);
		if (ret.ff + ret.ss == 0) return res;
		update(res);
		int pos = 0;
		for (int i = 0; i < (int)(v.size()); i++) {
			if (v[i] == res) {
				v.erase(v.begin() + i);
				break;
			}
		}
	}
	// throw runtime_error("oh no");
	return -1;
}

Compilation message

prize.cpp: In function 'int pquery(int)':
prize.cpp:31:6: warning: unused variable 'n' [-Wunused-variable]
   31 |  int n = (int)(bit.size()) - 1;
      |      ^
prize.cpp: In function 'int find_best(int)':
prize.cpp:74:7: warning: unused variable 'pos' [-Wunused-variable]
   74 |   int pos = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3416 KB Output is correct
2 Correct 5 ms 3416 KB Output is correct
3 Correct 4 ms 3416 KB Output is correct
4 Correct 4 ms 3416 KB Output is correct
5 Correct 3 ms 3416 KB Output is correct
6 Correct 3 ms 3416 KB Output is correct
7 Correct 5 ms 3500 KB Output is correct
8 Correct 3 ms 3416 KB Output is correct
9 Correct 5 ms 3416 KB Output is correct
10 Correct 4 ms 3416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 4 ms 3416 KB Output is correct
3 Correct 4 ms 3416 KB Output is correct
4 Correct 4 ms 3572 KB Output is correct
5 Correct 4 ms 3416 KB Output is correct
6 Correct 4 ms 3416 KB Output is correct
7 Correct 4 ms 3440 KB Output is correct
8 Correct 4 ms 3416 KB Output is correct
9 Correct 4 ms 3416 KB Output is correct
10 Correct 4 ms 3416 KB Output is correct
11 Correct 4 ms 3416 KB Output is correct
12 Correct 3 ms 3416 KB Output is correct
13 Correct 8 ms 3416 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 10 ms 3568 KB Output is correct
16 Correct 54 ms 3416 KB Output is correct
17 Correct 5 ms 3416 KB Output is correct
18 Partially correct 52 ms 3416 KB Partially correct - number of queries: 5981
19 Correct 5 ms 3416 KB Output is correct
20 Correct 9 ms 1880 KB Output is correct
21 Correct 17 ms 3664 KB Output is correct
22 Correct 7 ms 3584 KB Output is correct
23 Correct 4 ms 3584 KB Output is correct
24 Correct 4 ms 3416 KB Output is correct
25 Correct 31 ms 3572 KB Output is correct
26 Correct 24 ms 3556 KB Output is correct
27 Correct 4 ms 3416 KB Output is correct
28 Partially correct 53 ms 3664 KB Partially correct - number of queries: 5498
29 Correct 41 ms 3564 KB Output is correct
30 Partially correct 57 ms 3664 KB Partially correct - number of queries: 5897
31 Correct 3 ms 3576 KB Output is correct
32 Correct 5 ms 3416 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 19 ms 3556 KB Output is correct
35 Correct 4 ms 3416 KB Output is correct
36 Correct 21 ms 3820 KB Output is correct
37 Correct 6 ms 3416 KB Output is correct
38 Correct 5 ms 3416 KB Output is correct
39 Correct 27 ms 3560 KB Output is correct
40 Partially correct 45 ms 3564 KB Partially correct - number of queries: 5140
41 Correct 28 ms 3664 KB Output is correct
42 Correct 28 ms 3416 KB Output is correct
43 Correct 30 ms 3416 KB Output is correct
44 Correct 22 ms 3416 KB Output is correct
45 Correct 20 ms 3416 KB Output is correct
46 Correct 5 ms 3416 KB Output is correct
47 Correct 21 ms 3416 KB Output is correct
48 Correct 32 ms 3564 KB Output is correct
49 Correct 7 ms 3672 KB Output is correct
50 Partially correct 50 ms 3416 KB Partially correct - number of queries: 5953
51 Correct 29 ms 3920 KB Output is correct
52 Correct 3 ms 3416 KB Output is correct
53 Correct 4 ms 3416 KB Output is correct
54 Correct 17 ms 3672 KB Output is correct
55 Correct 4 ms 3416 KB Output is correct
56 Partially correct 59 ms 3560 KB Partially correct - number of queries: 5958
57 Correct 33 ms 3416 KB Output is correct
58 Correct 33 ms 3568 KB Output is correct
59 Correct 32 ms 3664 KB Output is correct
60 Correct 20 ms 3416 KB Output is correct
61 Correct 5 ms 3416 KB Output is correct
62 Correct 4 ms 3416 KB Output is correct
63 Correct 5 ms 3416 KB Output is correct
64 Correct 4 ms 3416 KB Output is correct
65 Correct 8 ms 3416 KB Output is correct
66 Correct 67 ms 3564 KB Output is correct
67 Correct 13 ms 3412 KB Output is correct
68 Correct 7 ms 3416 KB Output is correct
69 Correct 56 ms 3560 KB Output is correct
70 Correct 14 ms 3416 KB Output is correct
71 Partially correct 60 ms 3560 KB Partially correct - number of queries: 6627
72 Correct 6 ms 3416 KB Output is correct
73 Partially correct 55 ms 3812 KB Partially correct - number of queries: 6538
74 Partially correct 57 ms 3560 KB Partially correct - number of queries: 6583
75 Correct 4 ms 3416 KB Output is correct
76 Partially correct 71 ms 3564 KB Partially correct - number of queries: 5751
77 Partially correct 57 ms 3564 KB Partially correct - number of queries: 6056
78 Correct 8 ms 3672 KB Output is correct
79 Correct 25 ms 3568 KB Output is correct
80 Partially correct 58 ms 3664 KB Partially correct - number of queries: 6031
81 Partially correct 52 ms 3416 KB Partially correct - number of queries: 6132
82 Partially correct 58 ms 3668 KB Partially correct - number of queries: 5945
83 Correct 5 ms 3416 KB Output is correct
84 Partially correct 53 ms 3556 KB Partially correct - number of queries: 5114
85 Partially correct 58 ms 3416 KB Partially correct - number of queries: 6094
86 Correct 40 ms 3416 KB Output is correct
87 Correct 6 ms 3416 KB Output is correct
88 Correct 28 ms 3556 KB Output is correct
89 Correct 28 ms 3560 KB Output is correct
90 Correct 4 ms 3416 KB Output is correct
91 Correct 25 ms 3416 KB Output is correct
92 Correct 34 ms 3672 KB Output is correct
93 Correct 33 ms 3416 KB Output is correct
94 Correct 29 ms 3560 KB Output is correct
95 Correct 44 ms 3568 KB Output is correct
96 Correct 30 ms 3664 KB Output is correct
97 Correct 24 ms 3416 KB Output is correct