답안 #1012164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012164 2024-07-01T18:35:35 Z Tob 커다란 상품 (IOI17_prize) C++14
20 / 100
57 ms 5692 KB
#include <bits/stdc++.h>

#include "prize.h"

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int val(int x) {
	uniform_int_distribution <int> rnd(0, x-1);
	return rnd(rng);
}
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;

vector<int> ask(int i) {
	query_count++;
	if(query_count > max_q) {
		cerr << "Query limit exceeded" << endl;
		exit(0);
	}

	if(i < 0 || i >= n) {
		cerr << "Bad index: " << i << endl;
		exit(0);
	}

	vector<int> res(2);
	res[0] = rank_count[g[i] - 1][i + 1];
	res[1] = rank_count[g[i] - 1][n] - res[0];
	return res;
}
*/
const int B = 250, N = 2e5 + 7;
vector <int> ans[N];

vector <int> Ask(int x) {
	if (ans[x].empty()) ans[x] = ask(x);
	return ans[x];
}

int find_best(int n) {
	vector <int> x, v;
	int d = 0, la = -1, cnt = 0;
	for (int i = 0; i < 20; i++) {
		x = Ask(val(n));
		d = max(d, x[0]+x[1]);
	}
	for (int i = 0; i < n; i += B) {
		int l = i, r = min(i+B, n)-1;
		x = Ask(r);
		while (x[0] + x[1] < d && r >= l) {
			if (x[0]+x[1] == 0) return r;
			r--;
			if (l <= r) x = Ask(r);
		}
		if (l > r) continue;
		int z = x[0]-cnt;
		while (z--) {
			int lo = l, hi = r;
			while (lo < hi) {
				int mid = (lo + hi) / 2;
				x = Ask(mid);
				if (x[0] + x[1] < d || x[0] > cnt) hi = mid;
				else lo = mid+1;
			}
			x = Ask(lo);
			if (x[0]+x[1] == 0) return lo;
			cnt++;
			l = lo+1;
		}
	}
	
	return 0;
}
/*
int main() {
	n = 2e5;
//	cin >> n;
	vector <int> v, u;
	v.pb(1);
	ll sum = 1;
	for (int i = 0; sum <= n; i++) {
		ll x = v.back();
		ll kol = (ll)x*x+1+val(3);
		if (sum+kol > n) {
			v[v.size()-1] += n-sum;
			break;
		}
		else {
			v.pb(kol);
			sum += kol;
		}		
	}
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i]; j++) u.pb(i+1);
	}
	shuffle(all(u), rng);

	g.resize(n);
	int p = 0;
	for(int i = 0; i < n; i++) {
//		cin >> g[i];
		g[i] = u[i];
		if (g[i] == 1) p = i;
//		cout << g[i] << " ";
		if(g[i] < 1) {
			cerr << "Invalid rank " << g[i] << " at index " << i << endl;
			exit(0);
		}
	}
//	cout << "\n";

	int max_rank = *max_element(g.begin(), g.end());

	rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
	for(int r = 0; r <= max_rank; r++) {
		for(int i = 1; i <= n; i++) {
			rank_count[r][i] = rank_count[r][i - 1];
			if(g[i - 1] == r)
			  rank_count[r][i]++;
		}
	}

	for(int i = 0; i <= n; i++)
		for(int r = 1; r <= max_rank; r++)
			rank_count[r][i] += rank_count[r - 1][i];

	int res = find_best(n);
	cout << res << endl << "Query count: " << query_count << endl;

	return 0;
}
*/

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:56:13: warning: unused variable 'la' [-Wunused-variable]
   56 |  int d = 0, la = -1, cnt = 0;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 4 ms 5144 KB Output is correct
4 Correct 7 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 4 ms 4952 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 7 ms 5208 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 5 ms 4952 KB Output is correct
8 Correct 4 ms 4952 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 4 ms 4952 KB Output is correct
11 Correct 4 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 7 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 5 ms 5132 KB Output is correct
16 Correct 18 ms 5220 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 21 ms 5208 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 9 ms 5208 KB Output is correct
21 Correct 8 ms 4952 KB Output is correct
22 Correct 4 ms 4952 KB Output is correct
23 Correct 3 ms 4952 KB Output is correct
24 Correct 2 ms 4952 KB Output is correct
25 Correct 15 ms 5160 KB Output is correct
26 Correct 15 ms 5204 KB Output is correct
27 Correct 3 ms 4952 KB Output is correct
28 Correct 15 ms 5208 KB Output is correct
29 Correct 15 ms 5460 KB Output is correct
30 Correct 21 ms 5460 KB Output is correct
31 Correct 2 ms 4952 KB Output is correct
32 Correct 7 ms 5392 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 9 ms 4956 KB Output is correct
35 Correct 5 ms 4952 KB Output is correct
36 Correct 7 ms 5132 KB Output is correct
37 Correct 3 ms 4952 KB Output is correct
38 Correct 3 ms 4952 KB Output is correct
39 Correct 11 ms 5208 KB Output is correct
40 Correct 26 ms 5464 KB Output is correct
41 Correct 12 ms 5412 KB Output is correct
42 Correct 13 ms 5208 KB Output is correct
43 Correct 17 ms 5176 KB Output is correct
44 Correct 11 ms 5160 KB Output is correct
45 Correct 9 ms 5208 KB Output is correct
46 Correct 2 ms 4952 KB Output is correct
47 Correct 16 ms 4952 KB Output is correct
48 Correct 15 ms 5208 KB Output is correct
49 Correct 3 ms 4952 KB Output is correct
50 Correct 27 ms 5144 KB Output is correct
51 Correct 10 ms 4952 KB Output is correct
52 Correct 2 ms 4952 KB Output is correct
53 Correct 5 ms 4952 KB Output is correct
54 Correct 10 ms 4952 KB Output is correct
55 Correct 2 ms 4952 KB Output is correct
56 Correct 21 ms 5464 KB Output is correct
57 Correct 12 ms 5200 KB Output is correct
58 Correct 24 ms 5204 KB Output is correct
59 Correct 14 ms 5208 KB Output is correct
60 Correct 11 ms 5164 KB Output is correct
61 Correct 4 ms 4952 KB Output is correct
62 Correct 3 ms 4952 KB Output is correct
63 Correct 5 ms 4952 KB Output is correct
64 Correct 5 ms 4952 KB Output is correct
65 Correct 5 ms 4952 KB Output is correct
66 Correct 7 ms 5168 KB Output is correct
67 Correct 7 ms 4952 KB Output is correct
68 Correct 5 ms 4952 KB Output is correct
69 Correct 7 ms 4952 KB Output is correct
70 Correct 8 ms 5140 KB Output is correct
71 Correct 25 ms 5468 KB Output is correct
72 Correct 7 ms 4952 KB Output is correct
73 Correct 28 ms 5484 KB Output is correct
74 Correct 16 ms 5208 KB Output is correct
75 Correct 6 ms 4952 KB Output is correct
76 Correct 20 ms 5212 KB Output is correct
77 Correct 19 ms 5208 KB Output is correct
78 Correct 7 ms 5152 KB Output is correct
79 Correct 12 ms 5208 KB Output is correct
80 Correct 30 ms 5408 KB Output is correct
81 Correct 38 ms 5456 KB Output is correct
82 Correct 26 ms 5208 KB Output is correct
83 Correct 5 ms 5164 KB Output is correct
84 Correct 13 ms 5208 KB Output is correct
85 Correct 33 ms 5692 KB Output is correct
86 Incorrect 57 ms 5456 KB Incorrect
87 Halted 0 ms 0 KB -