Submission #420177

# Submission time Handle Problem Language Result Execution time Memory
420177 2021-06-08T07:09:32 Z oolimry The Big Prize (IOI17_prize) C++17
100 / 100
97 ms 10300 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
typedef unsigned long long lint;
typedef pair<lint,lint> ii;
 
int ans = -1;
int worst = 0;
vector<int> memo[200005];
bool isgood[200005];
bool tried[200005];
 
void dnc(vector<int> stuff, int good, int Lgood, int Rgood){
	if(good == 0) return;
	if(sz(stuff) == 0) return;
	//show3(good,Lgood,Rgood);
	
	int cnt = 0;
	int m = sz(stuff)/2;
	vector<int> S;
	for(int i = 0;i < sz(stuff);i++){
		int x = stuff[i];
		if(tried[x] and not isgood[x]) S.push_back(i);
		if(tried[x] and isgood[x]) cnt++;
	}
	
	if(sz(S) > 0) m = S[sz(S)/2];
	
	int orim = m;
		
	while(m < sz(stuff)){
		vector<int> res;
		if(tried[stuff[m]]) res = memo[stuff[m]];
		else res = ask(stuff[m]);
		if(res[0]+res[1] == 0) ans = stuff[m];
		
		if(res[0]+res[1] == worst){
			vector<int> L, R;
			for(int i = 0;i < orim;i++) L.push_back(stuff[i]);
			for(int i = m+1;i < sz(stuff);i++) R.push_back(stuff[i]);
			
			int btwgood = m-orim;
			
			dnc(L, res[0]-Lgood-btwgood, Lgood, res[1]+btwgood);
			dnc(R, res[1]-Rgood-btwgood, res[0]+btwgood, Rgood);
			return;
		}
		else m++;
	}
	
	vector<int> L;
	int btwgood = sz(stuff) - orim;
	for(int i = 0;i < orim;i++) L.push_back(stuff[i]);
	dnc(L, good-btwgood, Lgood, Rgood+btwgood);
}
 
int find_best(int n) {
	srand(12345);
	int taken = 0;
	while(taken < min(n, 500)){
		int i = rand()%n;
		if(tried[i]) continue;
		
		tried[i] = 1;
		vector<int> res = ask(i);
		memo[i] = res;
		worst = max(worst,res[0]+res[1]); 
		if(res[0]+res[1] == 0) ans = i;
		taken++;
	}
	
	if(ans != -1) return ans;
	
	for(int i = 0;i < n;i++){
		if(tried[i]) isgood[i] = (memo[i][0]+memo[i][1] != worst);
	}
	
	vector<int> v;
	for(int i = 0;i < n;i++){
		v.push_back(i);
	}
	dnc(v, worst, 0, 0);
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 9396 KB Output is correct
2 Correct 15 ms 9448 KB Output is correct
3 Correct 16 ms 9324 KB Output is correct
4 Correct 15 ms 9268 KB Output is correct
5 Correct 13 ms 9260 KB Output is correct
6 Correct 12 ms 9384 KB Output is correct
7 Correct 15 ms 9268 KB Output is correct
8 Correct 12 ms 9400 KB Output is correct
9 Correct 14 ms 9268 KB Output is correct
10 Correct 15 ms 9664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9324 KB Output is correct
2 Correct 12 ms 9496 KB Output is correct
3 Correct 14 ms 9304 KB Output is correct
4 Correct 16 ms 9324 KB Output is correct
5 Correct 12 ms 9272 KB Output is correct
6 Correct 12 ms 9476 KB Output is correct
7 Correct 12 ms 9276 KB Output is correct
8 Correct 17 ms 9320 KB Output is correct
9 Correct 14 ms 9304 KB Output is correct
10 Correct 16 ms 9648 KB Output is correct
11 Correct 30 ms 9772 KB Output is correct
12 Correct 34 ms 9700 KB Output is correct
13 Correct 28 ms 9704 KB Output is correct
14 Correct 9 ms 4936 KB Output is correct
15 Correct 61 ms 9876 KB Output is correct
16 Correct 77 ms 9920 KB Output is correct
17 Correct 83 ms 9776 KB Output is correct
18 Correct 74 ms 9876 KB Output is correct
19 Correct 76 ms 9792 KB Output is correct
20 Correct 37 ms 7416 KB Output is correct
21 Correct 62 ms 9772 KB Output is correct
22 Correct 72 ms 9756 KB Output is correct
23 Correct 17 ms 9704 KB Output is correct
24 Correct 26 ms 9652 KB Output is correct
25 Correct 72 ms 9756 KB Output is correct
26 Correct 60 ms 9776 KB Output is correct
27 Correct 22 ms 9712 KB Output is correct
28 Correct 59 ms 9780 KB Output is correct
29 Correct 65 ms 9776 KB Output is correct
30 Correct 78 ms 9840 KB Output is correct
31 Correct 80 ms 9776 KB Output is correct
32 Correct 28 ms 9756 KB Output is correct
33 Correct 4 ms 4936 KB Output is correct
34 Correct 76 ms 9796 KB Output is correct
35 Correct 20 ms 9720 KB Output is correct
36 Correct 79 ms 9784 KB Output is correct
37 Correct 22 ms 9780 KB Output is correct
38 Correct 20 ms 9780 KB Output is correct
39 Correct 78 ms 9920 KB Output is correct
40 Correct 55 ms 9836 KB Output is correct
41 Correct 82 ms 9836 KB Output is correct
42 Correct 88 ms 9832 KB Output is correct
43 Correct 77 ms 9904 KB Output is correct
44 Correct 74 ms 9736 KB Output is correct
45 Correct 83 ms 9780 KB Output is correct
46 Correct 71 ms 9776 KB Output is correct
47 Correct 78 ms 9828 KB Output is correct
48 Correct 85 ms 9744 KB Output is correct
49 Correct 81 ms 9884 KB Output is correct
50 Correct 77 ms 9788 KB Output is correct
51 Correct 67 ms 9908 KB Output is correct
52 Correct 72 ms 9772 KB Output is correct
53 Correct 21 ms 9828 KB Output is correct
54 Correct 83 ms 9896 KB Output is correct
55 Correct 71 ms 9768 KB Output is correct
56 Correct 73 ms 9700 KB Output is correct
57 Correct 82 ms 9780 KB Output is correct
58 Correct 83 ms 9912 KB Output is correct
59 Correct 70 ms 9728 KB Output is correct
60 Correct 82 ms 9656 KB Output is correct
61 Correct 22 ms 9652 KB Output is correct
62 Correct 21 ms 9652 KB Output is correct
63 Correct 22 ms 9632 KB Output is correct
64 Correct 20 ms 9652 KB Output is correct
65 Correct 19 ms 9532 KB Output is correct
66 Correct 22 ms 9316 KB Output is correct
67 Correct 18 ms 9320 KB Output is correct
68 Correct 23 ms 9512 KB Output is correct
69 Correct 17 ms 9260 KB Output is correct
70 Correct 18 ms 9328 KB Output is correct
71 Correct 83 ms 9776 KB Output is correct
72 Correct 27 ms 9788 KB Output is correct
73 Correct 97 ms 9752 KB Output is correct
74 Correct 53 ms 9868 KB Output is correct
75 Correct 20 ms 9780 KB Output is correct
76 Correct 80 ms 9780 KB Output is correct
77 Correct 73 ms 9732 KB Output is correct
78 Correct 34 ms 9784 KB Output is correct
79 Correct 46 ms 9740 KB Output is correct
80 Correct 87 ms 9760 KB Output is correct
81 Correct 82 ms 9888 KB Output is correct
82 Correct 81 ms 9920 KB Output is correct
83 Correct 26 ms 9780 KB Output is correct
84 Correct 90 ms 9804 KB Output is correct
85 Correct 75 ms 9796 KB Output is correct
86 Correct 64 ms 10036 KB Output is correct
87 Correct 27 ms 9804 KB Output is correct
88 Correct 63 ms 10164 KB Output is correct
89 Correct 56 ms 10164 KB Output is correct
90 Correct 17 ms 9648 KB Output is correct
91 Correct 46 ms 10156 KB Output is correct
92 Correct 67 ms 10140 KB Output is correct
93 Correct 82 ms 10164 KB Output is correct
94 Correct 74 ms 10228 KB Output is correct
95 Correct 64 ms 10184 KB Output is correct
96 Correct 72 ms 10300 KB Output is correct
97 Correct 54 ms 10144 KB Output is correct