Submission #794810

# Submission time Handle Problem Language Result Execution time Memory
794810 2023-07-26T23:27:28 Z fatemetmhr The Big Prize (IOI17_prize) C++17
98.23 / 100
44 ms 2980 KB
//  ~ Be Name Khoda ~  //
 
#include "prize.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
typedef long long ll;
 
#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
 
const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;
 
 
pair <int, int> ans[maxn5];
bool mark[maxn5];
int mx = 0, done = 0, dim = -1, cnt = 0, per[maxn5];
 
 
 
pair <int, int> assk(int id){
	if(cnt > 10000)
		exit(0);
	if(!mark[id]){
		vector <int> x = ask(id);
		cnt++;
		mark[id] = true;
		ans[id].fi = x[0];
		ans[id].se = x[1];
	}
	mx = max(mx, ans[id].fi + ans[id].se);
	if(ans[id].fi + ans[id].se == 0)
		dim = id;
	return ans[id];
}
 
/*
int check(int l, int r){
	l = lower_bound(all(good), l) - good.begin();
	r = lower_bound(all(good), r) - good.begin();
	return r - l;
}
*/
 
void solve(int l, int r, int x){
	if(dim != -1 || x == 0 || r <= l)
		return;
	if(r - l <= 2 * x){
		done += x;
		int found = 0;
		for(int i = l; i < r; i++)
			per[i] = i;
		shuffle(per + l, per + r, rng);
		for(int i = l; i < r && found < x; i++){
			assk(per[i]);
			if(ans[per[i]].fi + ans[per[i]].se != mx)
				found++;
			if(dim != -1)
				return;
		}
		return;
	}
	/*
	int w = check(l, r);
	if(w != x){
		cout << l << ' ' << r << ' ' << x << ' ' << w << ' ' << endl;
		exit(0);
	}
	*/
	int mid = (l + r) >> 1;
	int ptl = mid, ptr = mid + 1;
	mid = -1;
	int found = 0;
	//cout << "entering " << l << ' ' << r << ' ' << x << ' ' << cnt << ' ' << done << ' ' << dim << endl;
	while((ptl >= l || ptr < r) && found < x){
		////cout << "now " << ptl << ' ' << ptr << endl;
		if(ptl >= l){
			assk(ptl);
			if(dim != -1)
				return;
			if(ans[ptl].fi + ans[ptl].se == mx){
				ptr--;
				mid = ptl;
				break;
			}
			else
				found++;
		}
		if(found == x)
			break;
		if(ptr < r){
			assk(ptr);
			if(dim != -1)
				return;
			if(ans[ptr].fi + ans[ptr].se == mx){
				ptl = max(ptl, l);
				mid = ptr;
				break;
			}
			else
				found++;
		}
		if(ptl >= l)
			ptl--;
		if(ptr < r)
			ptr++;
	}
	//cout << "done with " << cnt << ' ' << done << ' ' << found << endl;
	//cout << "solving " << l << ' ' << r << ' ' << x << ' ' << found << ' ' << ptl << ' ' << ptr << ' ' << mid << ' ' << ans[mid].fi << endl;
	if(found == x){
		done += found;
		for(int i = l; i < r; i++) if(mark[i] && ans[i].fi + ans[i].se == 0)
			dim = i;
		return;
	}
	//if(mid == -1){
	//	cout << l << ' ' << r << ' ' << x << ' ' << found << ' ' << done << ' ' << ptl << ' ' << ptr << endl;
	//}
	assert(mid != -1);
	int keep = 0, keepdone = done;
	if(ptl > l){
		int lef = ans[mid].fi - done;
		for(int i = ptl; i < mid; i++) if(mark[i] && ans[i].fi + ans[i].se != mx)
			lef--;
		keep = lef;
		solve(l, ptl, lef);
		if(dim != -1)
			return;
	}
	if(ptr + 1 < r){
		int rig = x - keep;
		for(int i = ptl; i <= min(r - 1, ptr); i++) if(mark[i] && ans[i].fi + ans[i].se != mx){
			rig--;
			done++;
		}
		//if(rig < 0){
		//	cout << "WAAA " << rig << ' ' << l << ' ' << r << ' ' << ptl << ' ' << mid << ' ' << ptr << ' ' << x << ' ' << keep << ' ' << keepdone << ' ' << ans[mid].fi << endl;
		//}
		//cout << "in " << rig << endl;
		solve(ptr + 1, r, rig);
 
	}
 
}
 
int find_best(int n){
	//*
	int tt = 450;
	while(tt--)
		assk(rng() % n);
	//*/
	//mx = 1;
	if(dim != -1)
		return dim;
	solve(0, n, mx);
	//assert(dim != -1);
	//cout << cnt << endl;
	return dim;
}
 
 
 
 

Compilation message

prize.cpp: In function 'void solve(int, int, int)':
prize.cpp:135:16: warning: unused variable 'keepdone' [-Wunused-variable]
  135 |  int keep = 0, keepdone = done;
      |                ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1616 KB Output is correct
2 Correct 6 ms 1584 KB Output is correct
3 Correct 3 ms 1544 KB Output is correct
4 Correct 5 ms 1520 KB Output is correct
5 Correct 2 ms 1592 KB Output is correct
6 Correct 5 ms 1572 KB Output is correct
7 Correct 4 ms 1488 KB Output is correct
8 Correct 3 ms 1532 KB Output is correct
9 Correct 5 ms 1488 KB Output is correct
10 Correct 5 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1544 KB Output is correct
2 Correct 5 ms 1616 KB Output is correct
3 Correct 5 ms 1580 KB Output is correct
4 Correct 4 ms 1616 KB Output is correct
5 Correct 4 ms 1456 KB Output is correct
6 Correct 5 ms 1488 KB Output is correct
7 Correct 6 ms 1556 KB Output is correct
8 Correct 6 ms 1620 KB Output is correct
9 Correct 5 ms 1480 KB Output is correct
10 Correct 4 ms 1488 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 5 ms 1488 KB Output is correct
13 Correct 9 ms 1712 KB Output is correct
14 Correct 3 ms 464 KB Output is correct
15 Correct 11 ms 1708 KB Output is correct
16 Correct 31 ms 2536 KB Output is correct
17 Correct 5 ms 1488 KB Output is correct
18 Correct 40 ms 2740 KB Output is correct
19 Correct 5 ms 1616 KB Output is correct
20 Correct 9 ms 1260 KB Output is correct
21 Correct 15 ms 1960 KB Output is correct
22 Correct 8 ms 1616 KB Output is correct
23 Correct 3 ms 1540 KB Output is correct
24 Correct 3 ms 1528 KB Output is correct
25 Correct 10 ms 2156 KB Output is correct
26 Correct 23 ms 2148 KB Output is correct
27 Correct 5 ms 1616 KB Output is correct
28 Correct 35 ms 2532 KB Output is correct
29 Correct 13 ms 2404 KB Output is correct
30 Correct 44 ms 2740 KB Output is correct
31 Correct 5 ms 1580 KB Output is correct
32 Correct 5 ms 1700 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 17 ms 1872 KB Output is correct
35 Correct 4 ms 1584 KB Output is correct
36 Correct 7 ms 1868 KB Output is correct
37 Correct 5 ms 1580 KB Output is correct
38 Correct 5 ms 1488 KB Output is correct
39 Correct 13 ms 1996 KB Output is correct
40 Correct 22 ms 2716 KB Output is correct
41 Correct 11 ms 2196 KB Output is correct
42 Correct 24 ms 2216 KB Output is correct
43 Correct 15 ms 2248 KB Output is correct
44 Correct 8 ms 2100 KB Output is correct
45 Correct 11 ms 1804 KB Output is correct
46 Correct 3 ms 1488 KB Output is correct
47 Correct 19 ms 1992 KB Output is correct
48 Correct 13 ms 2400 KB Output is correct
49 Correct 4 ms 1540 KB Output is correct
50 Correct 40 ms 2728 KB Output is correct
51 Correct 8 ms 2064 KB Output is correct
52 Correct 4 ms 1580 KB Output is correct
53 Correct 6 ms 1540 KB Output is correct
54 Correct 8 ms 2060 KB Output is correct
55 Correct 4 ms 1648 KB Output is correct
56 Correct 31 ms 2688 KB Output is correct
57 Correct 31 ms 2376 KB Output is correct
58 Correct 21 ms 2352 KB Output is correct
59 Correct 20 ms 2216 KB Output is correct
60 Correct 19 ms 2116 KB Output is correct
61 Correct 5 ms 1576 KB Output is correct
62 Correct 5 ms 1616 KB Output is correct
63 Correct 5 ms 1684 KB Output is correct
64 Correct 5 ms 1616 KB Output is correct
65 Correct 4 ms 1488 KB Output is correct
66 Correct 7 ms 1444 KB Output is correct
67 Correct 7 ms 1580 KB Output is correct
68 Correct 3 ms 1528 KB Output is correct
69 Correct 6 ms 1580 KB Output is correct
70 Correct 7 ms 1488 KB Output is correct
71 Partially correct 32 ms 2760 KB Partially correct - number of queries: 5177
72 Correct 8 ms 1872 KB Output is correct
73 Partially correct 35 ms 2980 KB Partially correct - number of queries: 5120
74 Partially correct 36 ms 2712 KB Partially correct - number of queries: 5150
75 Correct 6 ms 1596 KB Output is correct
76 Correct 39 ms 2784 KB Output is correct
77 Correct 18 ms 2612 KB Output is correct
78 Correct 9 ms 1852 KB Output is correct
79 Correct 23 ms 2376 KB Output is correct
80 Correct 30 ms 2584 KB Output is correct
81 Correct 42 ms 2640 KB Output is correct
82 Correct 39 ms 2592 KB Output is correct
83 Correct 6 ms 1616 KB Output is correct
84 Correct 41 ms 2540 KB Output is correct
85 Correct 24 ms 2572 KB Output is correct
86 Correct 17 ms 2232 KB Output is correct
87 Correct 7 ms 1688 KB Output is correct
88 Correct 20 ms 2192 KB Output is correct
89 Correct 14 ms 2484 KB Output is correct
90 Correct 6 ms 1488 KB Output is correct
91 Correct 17 ms 2104 KB Output is correct
92 Correct 6 ms 1744 KB Output is correct
93 Correct 25 ms 2464 KB Output is correct
94 Correct 23 ms 2464 KB Output is correct
95 Correct 32 ms 2640 KB Output is correct
96 Correct 34 ms 2448 KB Output is correct
97 Correct 26 ms 2420 KB Output is correct