Submission #613886

# Submission time Handle Problem Language Result Execution time Memory
613886 2022-07-30T12:26:50 Z thezomb1e The Big Prize (IOI17_prize) C++17
90 / 100
105 ms 11300 KB
#include "prize.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)

using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;

//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;

//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int find_best(int n) {
	vector<vector<int>> mem(n + 5, {-1, -1});
	auto myask = [&](int i) {
		if (mem[i][0] == -1) {
			return mem[i] = ask(i);
		} else {
			return mem[i];
		}
	};
	int mx = 0, mx_i;
	for (int i = 0; i < min(n, 480); i++) {
		vector<int> res = myask(i);
		int cur = res[0] + res[1];
		maxs(mx, cur);
		if (cur == mx) {
			mx_i = i;
		}
		if (cur == 0) return i;
	}
	int i = mx_i;
	while (i < n) {
		vector<int> cur = myask(i);
		int lo = i, hi = n - 1;
		int to = n;
		while (lo <= hi) {
			int mi = (lo + hi) / 2;
			vector<int> res = myask(mi);
			if (res[0] + res[1] == 0) return mi;
			if (res[0] + res[1] < mx) {
				to = mi;
				hi = mi - 1;
			} else {
				if (res[0] == cur[0]) {
					lo = mi + 1;
				} else {
					hi = mi - 1;
				}
			}
		}
		while (to < n) {
			vector<int> res = myask(to);
			if (res[0] + res[1] == 0) return to;
			if (res[0] + res[1] == mx) break;
			to++;
		}
		i = to;
	}
	return 0;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:59:28: warning: 'mx_i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |   vector<int> cur = myask(i);
      |                            ^
# Verdict Execution time Memory Grader output
1 Correct 14 ms 11168 KB Output is correct
2 Correct 14 ms 11160 KB Output is correct
3 Correct 15 ms 11216 KB Output is correct
4 Correct 21 ms 11216 KB Output is correct
5 Correct 15 ms 11216 KB Output is correct
6 Correct 11 ms 11216 KB Output is correct
7 Correct 15 ms 11296 KB Output is correct
8 Correct 16 ms 11172 KB Output is correct
9 Correct 21 ms 11168 KB Output is correct
10 Correct 12 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 11164 KB Output is correct
2 Correct 18 ms 11168 KB Output is correct
3 Correct 16 ms 11156 KB Output is correct
4 Correct 13 ms 11160 KB Output is correct
5 Correct 15 ms 11216 KB Output is correct
6 Correct 11 ms 11216 KB Output is correct
7 Correct 16 ms 11168 KB Output is correct
8 Correct 19 ms 11208 KB Output is correct
9 Correct 19 ms 11244 KB Output is correct
10 Correct 14 ms 11216 KB Output is correct
11 Correct 14 ms 11256 KB Output is correct
12 Correct 15 ms 11160 KB Output is correct
13 Correct 22 ms 11160 KB Output is correct
14 Correct 10 ms 1360 KB Output is correct
15 Correct 35 ms 11176 KB Output is correct
16 Partially correct 74 ms 11244 KB Partially correct - number of queries: 7188
17 Correct 15 ms 11152 KB Output is correct
18 Partially correct 105 ms 11156 KB Partially correct - number of queries: 8345
19 Correct 15 ms 11168 KB Output is correct
20 Correct 16 ms 5676 KB Output is correct
21 Correct 50 ms 11172 KB Output is correct
22 Correct 23 ms 11192 KB Output is correct
23 Correct 20 ms 11168 KB Output is correct
24 Correct 15 ms 11284 KB Output is correct
25 Correct 58 ms 11216 KB Output is correct
26 Correct 54 ms 11160 KB Output is correct
27 Correct 15 ms 11160 KB Output is correct
28 Partially correct 90 ms 11172 KB Partially correct - number of queries: 7874
29 Partially correct 85 ms 11164 KB Partially correct - number of queries: 6113
30 Partially correct 78 ms 11216 KB Partially correct - number of queries: 8279
31 Correct 13 ms 11184 KB Output is correct
32 Correct 29 ms 11148 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 42 ms 11168 KB Output is correct
35 Correct 16 ms 11164 KB Output is correct
36 Correct 37 ms 11164 KB Output is correct
37 Correct 19 ms 11160 KB Output is correct
38 Correct 18 ms 11152 KB Output is correct
39 Correct 46 ms 11144 KB Output is correct
40 Partially correct 89 ms 11216 KB Partially correct - number of queries: 7163
41 Partially correct 37 ms 11140 KB Partially correct - number of queries: 5209
42 Partially correct 70 ms 11144 KB Partially correct - number of queries: 5209
43 Correct 55 ms 11172 KB Output is correct
44 Correct 40 ms 11180 KB Output is correct
45 Correct 31 ms 11208 KB Output is correct
46 Correct 18 ms 11160 KB Output is correct
47 Correct 54 ms 11240 KB Output is correct
48 Partially correct 68 ms 11160 KB Partially correct - number of queries: 6305
49 Correct 17 ms 11164 KB Output is correct
50 Partially correct 102 ms 11152 KB Partially correct - number of queries: 8340
51 Correct 50 ms 11148 KB Output is correct
52 Correct 26 ms 11228 KB Output is correct
53 Correct 13 ms 11164 KB Output is correct
54 Correct 62 ms 11164 KB Output is correct
55 Correct 16 ms 11156 KB Output is correct
56 Partially correct 87 ms 11216 KB Partially correct - number of queries: 8344
57 Partially correct 72 ms 11152 KB Partially correct - number of queries: 6207
58 Partially correct 55 ms 11200 KB Partially correct - number of queries: 6289
59 Partially correct 64 ms 11148 KB Partially correct - number of queries: 5206
60 Correct 52 ms 11156 KB Output is correct
61 Correct 22 ms 11212 KB Output is correct
62 Correct 18 ms 11148 KB Output is correct
63 Correct 17 ms 11176 KB Output is correct
64 Correct 19 ms 11184 KB Output is correct
65 Correct 16 ms 11152 KB Output is correct
66 Correct 19 ms 11224 KB Output is correct
67 Correct 17 ms 11152 KB Output is correct
68 Correct 16 ms 11164 KB Output is correct
69 Correct 23 ms 11164 KB Output is correct
70 Correct 16 ms 11240 KB Output is correct
71 Partially correct 89 ms 11216 KB Partially correct - number of queries: 8257
72 Correct 28 ms 11216 KB Output is correct
73 Partially correct 44 ms 11268 KB Partially correct - number of queries: 8129
74 Partially correct 93 ms 11248 KB Partially correct - number of queries: 8190
75 Correct 16 ms 11216 KB Output is correct
76 Partially correct 47 ms 11216 KB Partially correct - number of queries: 7097
77 Partially correct 72 ms 11220 KB Partially correct - number of queries: 8411
78 Correct 30 ms 11144 KB Output is correct
79 Correct 29 ms 11164 KB Output is correct
80 Partially correct 101 ms 11188 KB Partially correct - number of queries: 8412
81 Partially correct 92 ms 11216 KB Partially correct - number of queries: 8394
82 Partially correct 86 ms 11176 KB Partially correct - number of queries: 8304
83 Correct 16 ms 11300 KB Output is correct
84 Partially correct 81 ms 11216 KB Partially correct - number of queries: 6925
85 Partially correct 58 ms 11236 KB Partially correct - number of queries: 8341
86 Correct 14 ms 11236 KB Output is correct
87 Correct 13 ms 11216 KB Output is correct
88 Correct 15 ms 11268 KB Output is correct
89 Correct 15 ms 11168 KB Output is correct
90 Correct 16 ms 11236 KB Output is correct
91 Correct 13 ms 11240 KB Output is correct
92 Correct 13 ms 11228 KB Output is correct
93 Correct 17 ms 11216 KB Output is correct
94 Correct 16 ms 11172 KB Output is correct
95 Correct 17 ms 11244 KB Output is correct
96 Correct 18 ms 11168 KB Output is correct
97 Correct 15 ms 11216 KB Output is correct