Submission #1048690

# Submission time Handle Problem Language Result Execution time Memory
1048690 2024-08-08T09:06:24 Z pcc The Big Prize (IOI17_prize) C++17
98.18 / 100
109 ms 3704 KB
#include "prize.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define pii pair<int,int>
#define fs first
#define sc second
mt19937 seed(712271227);
#define rnd(l,r) uniform_int_distribution<int>(l,r)(seed)

#ifdef LOCAL
const int lim = 3;
const int dt = 5;
#else
const int lim = 5000;
const int dt = 460;
#endif

const int mxn = 2e5+10;
pii dp[mxn];
int N;
int big = 1e9;
int ans = 0;
bool done = false;
int C = 0;
ordered_set<int> st;
pii rng;

pii req(int p){
	if(dp[p].fs != -1)return dp[p];
	C++;
	assert(C<=10000);
	auto re = ask(p);
	return (dp[p] = pii(re[0],re[1]));
}

int check(int p){
	auto re = req(p);
	if(!re.fs&&!re.sc)return 0;
	else if(N-re.fs-re.sc == big)return 2;
	else if(re.fs+re.sc == 1){
		if(re.fs == 1)rng.sc = p-1;
		else rng.fs = p+1;
		return 1;
	}
	else{
		st.insert(p);
		return 1;
	}
}

deque<pii> q;

void calc(){
	if(done)return;
	int l,r;
	if(rnd(0,1)){
		auto [a,b] = q.front();q.pop_front();
		l = a,r = b;
	}
	else{
		auto [a,b] = q.back();q.pop_back();
		l = a,r = b;
	}
	l = max(l,rng.fs);r = min(r,rng.sc);
	cerr<<"DFS: "<<l<<','<<r<<endl;
	while(l<=r){
		if(!check(l)){
			ans = l;
			done = true;
			return;
		}
		else if(check(l) == 1){
			l++;
		}
		else break;
	}
	while(l<=r){
		if(!check(r)){
			ans = r;
			done = true;
			return;
		}
		else if(check(r) == 1){
			r--;
		}
		else break;
	}
	if(l>=r)return;
	int cnt = req(r).fs+req(l).sc-(N-big);
	if(!cnt)return;
	cerr<<"CHECK: "<<l<<','<<r<<','<<cnt<<endl;
	assert(cnt>0);
	int mid = (l+r+1)>>1;
	if(check(mid) == 0){
		ans = mid;
		done = true;
		return;
	}
	if(l == r)return;
	if(l != mid)q.push_back(pii(l,mid));
	if(mid != r)q.push_back(pii(mid,r));
	return;
}

int find_best(int nn) {
	N = nn;
	int pt = 0;
	for(int i = 1;i*i<2e5;i++)pt = i;
	cerr<<pt<<endl;
	for(auto &i:dp)i = pii(-1,-1);
	if(N<=lim){
		for(int i = 0;i<N;i++){
			auto tmp = req(i);
			if(!tmp.fs&&!tmp.sc)return i;
		}
		assert(false);
		return 0;
	}
	vector<int> perm;
	for(int i = 0;i<N;i++)perm.push_back(i);
	shuffle(perm.begin(),perm.end(),seed);
	for(int i = 0;i<dt;i++){
		auto tmp = req(perm[i]);
		big = min(big,N-tmp.fs-tmp.sc);
		if(!tmp.fs&&!tmp.sc){
			return perm[i];
		}
	}
	cerr<<"BIG: "<<big<<endl;
	q.push_back(pii(0,N-1));
	rng = pii(0,N-1);
	while(!q.empty()&&!done)calc();
	if(!done)exit(0);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3024 KB Output is correct
2 Correct 6 ms 3120 KB Output is correct
3 Correct 7 ms 3120 KB Output is correct
4 Correct 7 ms 3024 KB Output is correct
5 Correct 5 ms 2924 KB Output is correct
6 Correct 5 ms 3120 KB Output is correct
7 Correct 6 ms 3024 KB Output is correct
8 Correct 6 ms 3024 KB Output is correct
9 Correct 6 ms 3160 KB Output is correct
10 Correct 6 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3124 KB Output is correct
2 Correct 7 ms 3120 KB Output is correct
3 Correct 7 ms 3024 KB Output is correct
4 Correct 7 ms 3024 KB Output is correct
5 Correct 5 ms 3120 KB Output is correct
6 Correct 6 ms 3116 KB Output is correct
7 Correct 6 ms 3120 KB Output is correct
8 Correct 6 ms 3120 KB Output is correct
9 Correct 6 ms 3024 KB Output is correct
10 Correct 6 ms 3024 KB Output is correct
11 Correct 9 ms 3116 KB Output is correct
12 Correct 10 ms 3120 KB Output is correct
13 Correct 16 ms 3120 KB Output is correct
14 Correct 2 ms 2136 KB Output is correct
15 Correct 14 ms 3116 KB Output is correct
16 Correct 56 ms 3184 KB Output is correct
17 Correct 36 ms 3216 KB Output is correct
18 Correct 25 ms 3116 KB Output is correct
19 Correct 72 ms 3196 KB Output is correct
20 Correct 17 ms 2516 KB Output is correct
21 Correct 53 ms 3032 KB Output is correct
22 Correct 35 ms 3176 KB Output is correct
23 Correct 10 ms 3116 KB Output is correct
24 Correct 13 ms 3160 KB Output is correct
25 Correct 29 ms 3132 KB Output is correct
26 Correct 61 ms 3236 KB Output is correct
27 Correct 7 ms 3116 KB Output is correct
28 Correct 26 ms 3200 KB Output is correct
29 Correct 59 ms 3228 KB Output is correct
30 Correct 54 ms 3224 KB Output is correct
31 Correct 44 ms 3180 KB Output is correct
32 Correct 13 ms 3024 KB Output is correct
33 Correct 1 ms 1880 KB Output is correct
34 Correct 81 ms 3124 KB Output is correct
35 Correct 9 ms 3120 KB Output is correct
36 Correct 82 ms 3704 KB Output is correct
37 Correct 8 ms 3116 KB Output is correct
38 Correct 7 ms 3024 KB Output is correct
39 Correct 47 ms 3024 KB Output is correct
40 Correct 53 ms 3248 KB Output is correct
41 Correct 78 ms 3188 KB Output is correct
42 Correct 80 ms 3024 KB Output is correct
43 Correct 71 ms 3272 KB Output is correct
44 Correct 50 ms 3024 KB Output is correct
45 Correct 35 ms 3028 KB Output is correct
46 Correct 75 ms 3460 KB Output is correct
47 Correct 87 ms 3216 KB Output is correct
48 Correct 71 ms 3024 KB Output is correct
49 Correct 52 ms 3196 KB Output is correct
50 Correct 58 ms 3024 KB Output is correct
51 Correct 75 ms 3192 KB Output is correct
52 Correct 41 ms 3024 KB Output is correct
53 Correct 9 ms 3116 KB Output is correct
54 Correct 30 ms 3120 KB Output is correct
55 Correct 55 ms 3024 KB Output is correct
56 Correct 50 ms 3204 KB Output is correct
57 Correct 44 ms 3024 KB Output is correct
58 Correct 43 ms 3024 KB Output is correct
59 Correct 52 ms 3004 KB Output is correct
60 Correct 53 ms 3204 KB Output is correct
61 Correct 7 ms 3024 KB Output is correct
62 Correct 7 ms 3024 KB Output is correct
63 Correct 7 ms 3120 KB Output is correct
64 Correct 7 ms 3024 KB Output is correct
65 Correct 7 ms 3124 KB Output is correct
66 Correct 5 ms 3024 KB Output is correct
67 Correct 7 ms 3024 KB Output is correct
68 Correct 8 ms 3024 KB Output is correct
69 Correct 6 ms 3024 KB Output is correct
70 Correct 9 ms 3024 KB Output is correct
71 Partially correct 109 ms 3540 KB Partially correct - number of queries: 5182
72 Correct 25 ms 3024 KB Output is correct
73 Partially correct 108 ms 3184 KB Partially correct - number of queries: 5056
74 Correct 85 ms 3024 KB Output is correct
75 Correct 10 ms 3024 KB Output is correct
76 Correct 78 ms 3024 KB Output is correct
77 Correct 62 ms 3212 KB Output is correct
78 Correct 13 ms 3024 KB Output is correct
79 Correct 39 ms 3024 KB Output is correct
80 Correct 89 ms 3316 KB Output is correct
81 Correct 67 ms 3024 KB Output is correct
82 Correct 58 ms 3052 KB Output is correct
83 Correct 7 ms 3024 KB Output is correct
84 Correct 39 ms 3196 KB Output is correct
85 Correct 64 ms 3024 KB Output is correct
86 Correct 23 ms 3024 KB Output is correct
87 Correct 15 ms 3024 KB Output is correct
88 Correct 47 ms 3096 KB Output is correct
89 Correct 19 ms 3024 KB Output is correct
90 Correct 7 ms 3024 KB Output is correct
91 Correct 46 ms 3024 KB Output is correct
92 Correct 7 ms 3024 KB Output is correct
93 Correct 90 ms 3088 KB Output is correct
94 Correct 74 ms 3020 KB Output is correct
95 Correct 66 ms 3292 KB Output is correct
96 Correct 35 ms 3236 KB Output is correct
97 Correct 15 ms 3024 KB Output is correct