Submission #782414

# Submission time Handle Problem Language Result Execution time Memory
782414 2023-07-13T23:53:41 Z GusterGoose27 The Big Prize (IOI17_prize) C++17
100 / 100
43 ms 1696 KB
#include "prize.h"

#include <bits/stdc++.h>

using namespace std;

int range[5];

int s = -1;
// vector<int> big;
map<int, vector<int>> cache;

vector<int> get(int i) {
	if (cache.find(i) == cache.end()) cache[i] = ask(i);
	return cache[i];
}

int ans;

bool find(vector<int> &cur, vector<int> &nxt, int l, int r, int num_big, int lf = 0, int rf = 0) { // there are at least num_big big things
	if (l > r) return 1;
	if (num_big == r-l+1) return 1;
	if (l == r) {
		nxt.push_back(cur[l]);
		return 1;
	}
	int mid = (l+r)/2;
	int lq = mid;
	int numl, numr;
	while (lq >= l) {
		vector<int> res = get(cur[lq]);
		if (res[0] == 0 && res[1] == 0) {
			ans = cur[lq];
			return 1;
		}
		if (res[0]+res[1] < s) {
			nxt.push_back(cur[lq]);
			lq--;
			continue;
		}
		else if (res[0]+res[1] == s) {
			// big.push_back(cur[lq]);
			numl = res[0]-lf;
			numr = res[1]-rf-mid+lq;
			break;
		} else { // need to reset
			nxt.clear();
			// big.clear();
			s = res[0]+res[1];
			return 0;			
		}
	}
	if (lq == l-1) {
		if (!find(cur, nxt, mid+1, r, num_big, lf+mid-lq, rf)) return 0;
	}
	else {
		if (!find(cur, nxt, l, lq-1, lq-l-numl, lf, rf+numr+mid-lq)) return 0;
		if (!find(cur, nxt, mid+1, r, r-mid-numr, lf+numl+mid-lq, rf)) return 0;
	}
	return 1;
}

int solve(vector<int> &pos) {
	if (pos.size() == 1) return pos[0];
	vector<int> npos;
	s = -1;
	bool b;
	ans = -1;
	do {
		b = find(pos, npos, 0, pos.size()-1, 0);
	} while (!b);
	if (ans != -1) return ans;
	sort(npos.begin(), npos.end());
	return solve(npos);
}

int find_best(int n) {
	// range[0] = 1;
	// range[1] = 2;
	// range[2] = 5;
	// range[3] = 26;
	// range[4] = 677;
	vector<int> pos(n);
	iota(pos.begin(), pos.end(), 0);
	return solve(pos);
}

Compilation message

prize.cpp: In function 'bool find(std::vector<int>&, std::vector<int>&, int, int, int, int, int)':
prize.cpp:57:49: warning: 'numr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |   if (!find(cur, nxt, l, lq-1, lq-l-numl, lf, rf+numr+mid-lq)) return 0;
      |                                               ~~^~~~~
prize.cpp:57:12: warning: 'numl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |   if (!find(cur, nxt, l, lq-1, lq-l-numl, lf, rf+numr+mid-lq)) return 0;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1040 KB Output is correct
4 Correct 1 ms 1056 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 1056 KB Output is correct
7 Correct 1 ms 1060 KB Output is correct
8 Correct 1 ms 1056 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1064 KB Output is correct
2 Correct 1 ms 1056 KB Output is correct
3 Correct 1 ms 1060 KB Output is correct
4 Correct 1 ms 1052 KB Output is correct
5 Correct 1 ms 1060 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 1060 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 3 ms 1052 KB Output is correct
12 Correct 4 ms 1104 KB Output is correct
13 Correct 3 ms 1056 KB Output is correct
14 Correct 7 ms 396 KB Output is correct
15 Correct 38 ms 1444 KB Output is correct
16 Correct 20 ms 1540 KB Output is correct
17 Correct 40 ms 1440 KB Output is correct
18 Correct 18 ms 1652 KB Output is correct
19 Correct 33 ms 1504 KB Output is correct
20 Correct 19 ms 968 KB Output is correct
21 Correct 34 ms 1436 KB Output is correct
22 Correct 22 ms 1356 KB Output is correct
23 Correct 2 ms 1056 KB Output is correct
24 Correct 4 ms 1060 KB Output is correct
25 Correct 29 ms 1396 KB Output is correct
26 Correct 41 ms 1436 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 16 ms 1460 KB Output is correct
29 Correct 30 ms 1404 KB Output is correct
30 Correct 19 ms 1544 KB Output is correct
31 Correct 34 ms 1648 KB Output is correct
32 Correct 4 ms 1060 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 39 ms 1432 KB Output is correct
35 Correct 2 ms 1104 KB Output is correct
36 Correct 35 ms 1488 KB Output is correct
37 Correct 5 ms 1040 KB Output is correct
38 Correct 2 ms 1056 KB Output is correct
39 Correct 35 ms 1640 KB Output is correct
40 Correct 15 ms 1464 KB Output is correct
41 Correct 28 ms 1428 KB Output is correct
42 Correct 36 ms 1516 KB Output is correct
43 Correct 16 ms 1484 KB Output is correct
44 Correct 33 ms 1696 KB Output is correct
45 Correct 15 ms 1476 KB Output is correct
46 Correct 17 ms 1528 KB Output is correct
47 Correct 34 ms 1388 KB Output is correct
48 Correct 29 ms 1520 KB Output is correct
49 Correct 19 ms 1624 KB Output is correct
50 Correct 37 ms 1476 KB Output is correct
51 Correct 30 ms 1528 KB Output is correct
52 Correct 17 ms 1536 KB Output is correct
53 Correct 1 ms 1100 KB Output is correct
54 Correct 17 ms 1536 KB Output is correct
55 Correct 27 ms 1556 KB Output is correct
56 Correct 43 ms 1416 KB Output is correct
57 Correct 35 ms 1488 KB Output is correct
58 Correct 37 ms 1492 KB Output is correct
59 Correct 26 ms 1500 KB Output is correct
60 Correct 21 ms 1472 KB Output is correct
61 Correct 2 ms 1104 KB Output is correct
62 Correct 1 ms 1104 KB Output is correct
63 Correct 2 ms 1052 KB Output is correct
64 Correct 1 ms 1064 KB Output is correct
65 Correct 1 ms 1104 KB Output is correct
66 Correct 5 ms 1060 KB Output is correct
67 Correct 2 ms 976 KB Output is correct
68 Correct 3 ms 1104 KB Output is correct
69 Correct 3 ms 1104 KB Output is correct
70 Correct 1 ms 1104 KB Output is correct
71 Correct 38 ms 1480 KB Output is correct
72 Correct 3 ms 1096 KB Output is correct
73 Correct 30 ms 1484 KB Output is correct
74 Correct 26 ms 1520 KB Output is correct
75 Correct 2 ms 1104 KB Output is correct
76 Correct 23 ms 1452 KB Output is correct
77 Correct 33 ms 1484 KB Output is correct
78 Correct 5 ms 1108 KB Output is correct
79 Correct 14 ms 1184 KB Output is correct
80 Correct 34 ms 1536 KB Output is correct
81 Correct 24 ms 1684 KB Output is correct
82 Correct 28 ms 1536 KB Output is correct
83 Correct 2 ms 1104 KB Output is correct
84 Correct 34 ms 1352 KB Output is correct
85 Correct 29 ms 1472 KB Output is correct
86 Correct 6 ms 1104 KB Output is correct
87 Correct 2 ms 1104 KB Output is correct
88 Correct 5 ms 1064 KB Output is correct
89 Correct 6 ms 1164 KB Output is correct
90 Correct 1 ms 976 KB Output is correct
91 Correct 3 ms 1104 KB Output is correct
92 Correct 4 ms 1128 KB Output is correct
93 Correct 3 ms 1120 KB Output is correct
94 Correct 3 ms 1104 KB Output is correct
95 Correct 4 ms 1104 KB Output is correct
96 Correct 3 ms 1104 KB Output is correct
97 Correct 1 ms 976 KB Output is correct