답안 #1012199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012199 2024-07-01T19:37:00 Z Tob 커다란 상품 (IOI17_prize) C++14
100 / 100
26 ms 5560 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 < n; i += B) {
		x = Ask(min(i+B, n)-1);
		d = max(d, x[0]+x[1]);
	}
	for (int i = 0; i < min(n, max(0, 510-n/B)); i++) {
		x = Ask(i);
		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);
		int cnt2 = 0;
		while (x[0] + x[1] < d && r >= l) {
			if (x[0]+x[1] == 0) return r;
			r--;
			cnt2++;
			if (l <= r) x = Ask(r);
		}
		int z = 0;
		if (l <= r) 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;
		}
		cnt += cnt2;
	}
	
	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 3 ms 4952 KB Output is correct
2 Correct 5 ms 4952 KB Output is correct
3 Correct 5 ms 4952 KB Output is correct
4 Correct 5 ms 4952 KB Output is correct
5 Correct 6 ms 5136 KB Output is correct
6 Correct 4 ms 4952 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 5 ms 4952 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 6 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5208 KB Output is correct
2 Correct 5 ms 4952 KB Output is correct
3 Correct 5 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 4 ms 4952 KB Output is correct
7 Correct 7 ms 4952 KB Output is correct
8 Correct 8 ms 4952 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 5 ms 4952 KB Output is correct
11 Correct 5 ms 5208 KB Output is correct
12 Correct 5 ms 4952 KB Output is correct
13 Correct 5 ms 5208 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 7 ms 4952 KB Output is correct
16 Correct 18 ms 5208 KB Output is correct
17 Correct 6 ms 4952 KB Output is correct
18 Correct 21 ms 5208 KB Output is correct
19 Correct 5 ms 5208 KB Output is correct
20 Correct 7 ms 5160 KB Output is correct
21 Correct 14 ms 4952 KB Output is correct
22 Correct 5 ms 4952 KB Output is correct
23 Correct 4 ms 4952 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 13 ms 5208 KB Output is correct
26 Correct 10 ms 5560 KB Output is correct
27 Correct 7 ms 5144 KB Output is correct
28 Correct 22 ms 5412 KB Output is correct
29 Correct 18 ms 5464 KB Output is correct
30 Correct 25 ms 5256 KB Output is correct
31 Correct 3 ms 4952 KB Output is correct
32 Correct 4 ms 4952 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 9 ms 5160 KB Output is correct
35 Correct 3 ms 4952 KB Output is correct
36 Correct 5 ms 4952 KB Output is correct
37 Correct 5 ms 4952 KB Output is correct
38 Correct 4 ms 5160 KB Output is correct
39 Correct 12 ms 5208 KB Output is correct
40 Correct 18 ms 5208 KB Output is correct
41 Correct 9 ms 5204 KB Output is correct
42 Correct 9 ms 5224 KB Output is correct
43 Correct 12 ms 5204 KB Output is correct
44 Correct 8 ms 4952 KB Output is correct
45 Correct 13 ms 5168 KB Output is correct
46 Correct 8 ms 4952 KB Output is correct
47 Correct 15 ms 4952 KB Output is correct
48 Correct 15 ms 5216 KB Output is correct
49 Correct 6 ms 4952 KB Output is correct
50 Correct 19 ms 5208 KB Output is correct
51 Correct 11 ms 4952 KB Output is correct
52 Correct 5 ms 4952 KB Output is correct
53 Correct 3 ms 4952 KB Output is correct
54 Correct 11 ms 5208 KB Output is correct
55 Correct 5 ms 5140 KB Output is correct
56 Correct 19 ms 5208 KB Output is correct
57 Correct 16 ms 5208 KB Output is correct
58 Correct 24 ms 5512 KB Output is correct
59 Correct 15 ms 5424 KB Output is correct
60 Correct 9 ms 4952 KB Output is correct
61 Correct 3 ms 4952 KB Output is correct
62 Correct 4 ms 4952 KB Output is correct
63 Correct 4 ms 4952 KB Output is correct
64 Correct 3 ms 4952 KB Output is correct
65 Correct 4 ms 4952 KB Output is correct
66 Correct 5 ms 4952 KB Output is correct
67 Correct 6 ms 4952 KB Output is correct
68 Correct 7 ms 4952 KB Output is correct
69 Correct 4 ms 4952 KB Output is correct
70 Correct 3 ms 4952 KB Output is correct
71 Correct 17 ms 5208 KB Output is correct
72 Correct 5 ms 4952 KB Output is correct
73 Correct 20 ms 5248 KB Output is correct
74 Correct 21 ms 5472 KB Output is correct
75 Correct 5 ms 4952 KB Output is correct
76 Correct 21 ms 5208 KB Output is correct
77 Correct 15 ms 5220 KB Output is correct
78 Correct 5 ms 5160 KB Output is correct
79 Correct 10 ms 5168 KB Output is correct
80 Correct 16 ms 5456 KB Output is correct
81 Correct 26 ms 5292 KB Output is correct
82 Correct 19 ms 5168 KB Output is correct
83 Correct 4 ms 4952 KB Output is correct
84 Correct 19 ms 5436 KB Output is correct
85 Correct 22 ms 5436 KB Output is correct
86 Correct 8 ms 4952 KB Output is correct
87 Correct 4 ms 4952 KB Output is correct
88 Correct 4 ms 4952 KB Output is correct
89 Correct 6 ms 4952 KB Output is correct
90 Correct 4 ms 4952 KB Output is correct
91 Correct 6 ms 4952 KB Output is correct
92 Correct 6 ms 5208 KB Output is correct
93 Correct 7 ms 4952 KB Output is correct
94 Correct 7 ms 5208 KB Output is correct
95 Correct 6 ms 4952 KB Output is correct
96 Correct 5 ms 4952 KB Output is correct
97 Correct 6 ms 4952 KB Output is correct