Submission #137549

# Submission time Handle Problem Language Result Execution time Memory
137549 2019-07-28T06:25:03 Z MAMBA The Big Prize (IOI17_prize) C++17
20 / 100
78 ms 2732 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define all(x) x.begin(),x.end()

typedef vector<int> vi;

map<int , vi> mp;
inline vi F(int i) {
	if (mp.count(i)) return mp[i];
	if (mp.size() + 1 > 10000) assert(0);
	return (mp[i] = ask(i));
}

inline int sum(vi me) {
	return accumulate(all(me) , 0);
}

int least, ans, ltof , rtof;
bitset<400000> mark;

void solve(int l , int r, int le , int ri) {

	if (l >= rtof || r <= ltof) return;
	if (ans != -1) return;
	if (l >= r) return;
	if (le + ri == least) return;
	int mid = l + r >> 1;
	bool happy = false;
	rep(i , 0 , r - l) {
		if (i & 1) mid -= i;
		else mid += i;
		vi me = F(mid);
		if (me[0] == 0) ltof = max(ltof , mid - 1);
		if (me[1] == 0) rtof = min(rtof , mid + 1);
		mark[mid] = true;
		if (sum(me) == 0) ans = mid;
		if (sum(me) == least) {
			happy = true;
			break;
		}
	}

	if (!happy) return;

	int ptr = l;
	while (!mark[ptr]) ptr++;
	int ptr2 = ptr;
	while (sum(F(ptr2)) != least) ptr2++;

	int 	ptr3 = r - 1;
	while (!mark[ptr3]) ptr3--;
	int ptr4 = ptr3;
	while (sum(F(ptr4)) != least) ptr4--;


	if (random() % 2) {
		solve(l , ptr , le , ptr2 - ptr + F(ptr2)[1]);


		solve(ptr3 + 1 , r , ptr3 - ptr4 + F(ptr4)[0], ri);
	}

	else {
		solve(l , ptr , le , ptr2 - ptr + F(ptr2)[1]);


		solve(ptr3 + 1 , r , ptr3 - ptr4 + F(ptr4)[0], ri);

	}
}

int find_best(int n) {

	mp.clear();
	rep(i , 0 , n) mark[i] = false;

	ltof = 0;
	rtof= n;

	least = -1; ans = -1;
	for (int i = 1; (i - 2) * (i - 2) <= n; i++) {
		least = max(least , sum(F(i - 1)));
		if (sum(F(i - 1)) == 0) return i - 1;
	}


	solve(0 , n , 0 , 0);

	return ans;
}

Compilation message

prize.cpp: In function 'void solve(int, int, int, int)':
prize.cpp:31:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 6 ms 436 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 464 KB Output is correct
6 Correct 11 ms 248 KB Output is correct
7 Correct 10 ms 376 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
9 Correct 8 ms 352 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 6 ms 368 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 6 ms 436 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 9 ms 564 KB Output is correct
12 Correct 6 ms 484 KB Output is correct
13 Correct 14 ms 432 KB Output is correct
14 Correct 5 ms 248 KB Output is correct
15 Correct 15 ms 536 KB Output is correct
16 Correct 52 ms 760 KB Output is correct
17 Correct 5 ms 452 KB Output is correct
18 Correct 62 ms 772 KB Output is correct
19 Correct 6 ms 532 KB Output is correct
20 Correct 20 ms 504 KB Output is correct
21 Correct 26 ms 556 KB Output is correct
22 Correct 14 ms 376 KB Output is correct
23 Correct 7 ms 376 KB Output is correct
24 Correct 9 ms 308 KB Output is correct
25 Correct 35 ms 504 KB Output is correct
26 Correct 32 ms 516 KB Output is correct
27 Correct 8 ms 376 KB Output is correct
28 Correct 52 ms 760 KB Output is correct
29 Correct 41 ms 700 KB Output is correct
30 Correct 38 ms 836 KB Output is correct
31 Correct 7 ms 308 KB Output is correct
32 Correct 12 ms 504 KB Output is correct
33 Correct 2 ms 248 KB Output is correct
34 Correct 25 ms 504 KB Output is correct
35 Correct 10 ms 376 KB Output is correct
36 Correct 13 ms 576 KB Output is correct
37 Correct 9 ms 372 KB Output is correct
38 Correct 9 ms 376 KB Output is correct
39 Correct 32 ms 504 KB Output is correct
40 Correct 41 ms 708 KB Output is correct
41 Correct 40 ms 704 KB Output is correct
42 Correct 40 ms 636 KB Output is correct
43 Correct 38 ms 632 KB Output is correct
44 Correct 28 ms 540 KB Output is correct
45 Correct 22 ms 504 KB Output is correct
46 Correct 5 ms 368 KB Output is correct
47 Correct 28 ms 504 KB Output is correct
48 Correct 43 ms 632 KB Output is correct
49 Correct 8 ms 592 KB Output is correct
50 Correct 66 ms 964 KB Output is correct
51 Correct 34 ms 504 KB Output is correct
52 Correct 9 ms 376 KB Output is correct
53 Correct 11 ms 424 KB Output is correct
54 Correct 19 ms 768 KB Output is correct
55 Correct 7 ms 376 KB Output is correct
56 Correct 65 ms 908 KB Output is correct
57 Correct 47 ms 616 KB Output is correct
58 Correct 31 ms 740 KB Output is correct
59 Correct 38 ms 576 KB Output is correct
60 Correct 36 ms 628 KB Output is correct
61 Correct 9 ms 376 KB Output is correct
62 Correct 7 ms 376 KB Output is correct
63 Correct 10 ms 376 KB Output is correct
64 Correct 8 ms 376 KB Output is correct
65 Correct 9 ms 376 KB Output is correct
66 Correct 13 ms 432 KB Output is correct
67 Correct 10 ms 392 KB Output is correct
68 Correct 7 ms 312 KB Output is correct
69 Correct 8 ms 468 KB Output is correct
70 Correct 7 ms 592 KB Output is correct
71 Partially correct 65 ms 936 KB Partially correct - number of queries: 5207
72 Correct 18 ms 680 KB Output is correct
73 Partially correct 64 ms 940 KB Partially correct - number of queries: 5144
74 Partially correct 48 ms 1020 KB Partially correct - number of queries: 5171
75 Correct 10 ms 376 KB Output is correct
76 Correct 58 ms 748 KB Output is correct
77 Correct 61 ms 848 KB Output is correct
78 Correct 10 ms 424 KB Output is correct
79 Correct 34 ms 524 KB Output is correct
80 Correct 63 ms 760 KB Output is correct
81 Correct 53 ms 856 KB Output is correct
82 Correct 62 ms 840 KB Output is correct
83 Correct 11 ms 396 KB Output is correct
84 Correct 41 ms 752 KB Output is correct
85 Correct 62 ms 832 KB Output is correct
86 Runtime error 78 ms 2732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
87 Halted 0 ms 0 KB -