Submission #408664

# Submission time Handle Problem Language Result Execution time Memory
408664 2021-05-19T12:36:35 Z Kevin_Zhang_TW The Big Prize (IOI17_prize) C++17
100 / 100
69 ms 7508 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
 
#include "prize.h"
 
const int MAX_N = 300010;
 
vector<int> qry(int id) {
	static vector<int> mem[MAX_N];
	if (mem[id].size()) return mem[id];
	static int cnt;
	assert(++cnt <= 9000);
	return mem[id] = ask(id);
}
 
int sum(int id) { return qry(id)[0] + qry(id)[1]; }

int solve(int L, int R, int mxsum, int fr_small, int cnt_small) {
	if (L > R || cnt_small == 0) return 0;

	int M = L + R >> 1;

	if (sum(M) == mxsum) {
		int cnt = qry(M)[0], res = 0;
		return solve(L, M-1, mxsum, fr_small, cnt - fr_small) +
			solve(M+1, R, mxsum, cnt, cnt_small - (cnt - fr_small));
	}

	if (sum(M) == 0) return M;


	int NR = M, res = 0;
	while (NR >= L && sum(NR) < mxsum) {
		if (sum(NR) == 0) return NR;
		--NR;
	}
	if (NR >= L)
		res += solve(L, NR-1, mxsum, fr_small, qry(NR)[0] - fr_small);

	int NL = M;
	while (NL <= R && sum(NL) < mxsum) {
		if (sum(NL) == 0) return NL;
		++NL;
	}
	if (NL <= R)
		res += solve(NL+1, R, mxsum, qry(NL)[0], cnt_small - (qry(NL)[0] - fr_small));

	return res;
}
 
int find_best(int n) {
	int mxsum = 0, pos = -1, m = min(n, 500);
	for (int i = 0;i < m && mxsum < 27;++i) {
		chmax(mxsum, sum(i));
		if (mxsum == sum(i))
			pos = i;
		if (sum(i) == 0) return i;
	}
	return solve(pos+1, n-1, mxsum, qry(pos)[0], mxsum - pos);
}

Compilation message

prize.cpp: In function 'int solve(int, int, int, int, int)':
prize.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |  int M = L + R >> 1;
      |          ~~^~~
prize.cpp:38:24: warning: unused variable 'res' [-Wunused-variable]
   38 |   int cnt = qry(M)[0], res = 0;
      |                        ^~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7240 KB Output is correct
2 Correct 9 ms 7320 KB Output is correct
3 Correct 12 ms 7240 KB Output is correct
4 Correct 12 ms 7240 KB Output is correct
5 Correct 7 ms 7384 KB Output is correct
6 Correct 5 ms 7260 KB Output is correct
7 Correct 11 ms 7328 KB Output is correct
8 Correct 7 ms 7324 KB Output is correct
9 Correct 11 ms 7328 KB Output is correct
10 Correct 12 ms 7240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7384 KB Output is correct
2 Correct 11 ms 7240 KB Output is correct
3 Correct 12 ms 7328 KB Output is correct
4 Correct 10 ms 7240 KB Output is correct
5 Correct 11 ms 7240 KB Output is correct
6 Correct 5 ms 7360 KB Output is correct
7 Correct 12 ms 7244 KB Output is correct
8 Correct 13 ms 7240 KB Output is correct
9 Correct 7 ms 7344 KB Output is correct
10 Correct 10 ms 7240 KB Output is correct
11 Correct 11 ms 7240 KB Output is correct
12 Correct 10 ms 7356 KB Output is correct
13 Correct 11 ms 7324 KB Output is correct
14 Correct 19 ms 7240 KB Output is correct
15 Correct 37 ms 7492 KB Output is correct
16 Correct 57 ms 7476 KB Output is correct
17 Correct 58 ms 7360 KB Output is correct
18 Correct 28 ms 7480 KB Output is correct
19 Correct 61 ms 7448 KB Output is correct
20 Correct 32 ms 7468 KB Output is correct
21 Correct 43 ms 7452 KB Output is correct
22 Correct 21 ms 7436 KB Output is correct
23 Correct 8 ms 7384 KB Output is correct
24 Correct 10 ms 7320 KB Output is correct
25 Correct 56 ms 7320 KB Output is correct
26 Correct 63 ms 7328 KB Output is correct
27 Correct 16 ms 7240 KB Output is correct
28 Correct 41 ms 7360 KB Output is correct
29 Correct 22 ms 7464 KB Output is correct
30 Correct 59 ms 7368 KB Output is correct
31 Correct 57 ms 7452 KB Output is correct
32 Correct 12 ms 7240 KB Output is correct
33 Correct 5 ms 7240 KB Output is correct
34 Correct 56 ms 7488 KB Output is correct
35 Correct 14 ms 7368 KB Output is correct
36 Correct 61 ms 7456 KB Output is correct
37 Correct 9 ms 7328 KB Output is correct
38 Correct 13 ms 7232 KB Output is correct
39 Correct 28 ms 7460 KB Output is correct
40 Correct 24 ms 7428 KB Output is correct
41 Correct 27 ms 7468 KB Output is correct
42 Correct 48 ms 7360 KB Output is correct
43 Correct 39 ms 7376 KB Output is correct
44 Correct 37 ms 7444 KB Output is correct
45 Correct 25 ms 7464 KB Output is correct
46 Correct 27 ms 7508 KB Output is correct
47 Correct 37 ms 7488 KB Output is correct
48 Correct 27 ms 7456 KB Output is correct
49 Correct 62 ms 7348 KB Output is correct
50 Correct 50 ms 7488 KB Output is correct
51 Correct 49 ms 7416 KB Output is correct
52 Correct 61 ms 7400 KB Output is correct
53 Correct 13 ms 7324 KB Output is correct
54 Correct 50 ms 7360 KB Output is correct
55 Correct 51 ms 7488 KB Output is correct
56 Correct 66 ms 7360 KB Output is correct
57 Correct 48 ms 7360 KB Output is correct
58 Correct 27 ms 7508 KB Output is correct
59 Correct 35 ms 7476 KB Output is correct
60 Correct 48 ms 7452 KB Output is correct
61 Correct 12 ms 7240 KB Output is correct
62 Correct 13 ms 7332 KB Output is correct
63 Correct 10 ms 7328 KB Output is correct
64 Correct 12 ms 7240 KB Output is correct
65 Correct 5 ms 7192 KB Output is correct
66 Correct 7 ms 7376 KB Output is correct
67 Correct 5 ms 7312 KB Output is correct
68 Correct 10 ms 7348 KB Output is correct
69 Correct 11 ms 7232 KB Output is correct
70 Correct 5 ms 7368 KB Output is correct
71 Correct 63 ms 7352 KB Output is correct
72 Correct 11 ms 7240 KB Output is correct
73 Correct 63 ms 7456 KB Output is correct
74 Correct 61 ms 7360 KB Output is correct
75 Correct 11 ms 7240 KB Output is correct
76 Correct 58 ms 7360 KB Output is correct
77 Correct 66 ms 7360 KB Output is correct
78 Correct 12 ms 7296 KB Output is correct
79 Correct 43 ms 7344 KB Output is correct
80 Correct 63 ms 7360 KB Output is correct
81 Correct 48 ms 7464 KB Output is correct
82 Correct 69 ms 7392 KB Output is correct
83 Correct 14 ms 7240 KB Output is correct
84 Correct 57 ms 7360 KB Output is correct
85 Correct 64 ms 7436 KB Output is correct
86 Correct 7 ms 7376 KB Output is correct
87 Correct 5 ms 7240 KB Output is correct
88 Correct 11 ms 7240 KB Output is correct
89 Correct 10 ms 7240 KB Output is correct
90 Correct 7 ms 7340 KB Output is correct
91 Correct 11 ms 7240 KB Output is correct
92 Correct 10 ms 7344 KB Output is correct
93 Correct 9 ms 7352 KB Output is correct
94 Correct 13 ms 7344 KB Output is correct
95 Correct 15 ms 7352 KB Output is correct
96 Correct 14 ms 7240 KB Output is correct
97 Correct 11 ms 7240 KB Output is correct