Submission #834119

# Submission time Handle Problem Language Result Execution time Memory
834119 2023-08-22T10:56:10 Z caganyanmaz The Big Prize (IOI17_prize) C++17
90 / 100
78 ms 428 KB
#include <bits/stdc++.h>
#define pb push_back
#include "prize.h"
using namespace std;

//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif

constexpr static int BLOCK_SIZE = 500;
constexpr static int LBN = 5000; 
constexpr static int MXN = 2e5;
bitset<MXN> expensive;

int brute(int n);
int find_best(int n)
{
	// Get rid of smaller cases
	if (n < 5000)
		return brute(n);
	// Finding one cheap prize (getting expesive ones are better)
	int ecount = 0;
	vector<int> c;
	for (int i = 0; i < BLOCK_SIZE; i++)
	{
		vector<int> v = ask(i);
		c.pb(v[0] + v[1]);
		ecount = max(ecount, c.back());
	}
	int s = 0;
	vector<int> vv;
	for (int i = 0; i < BLOCK_SIZE; i++)
	{
		if (c[i] != ecount)
		{
			expensive[i] = true;
			vv.pb(i);
		}
	}
	while (vv.size() < ecount)
	{
		int l = 0, r = n;
		while (r - l > 1)
		{
			int m = l+r>>1;
			int j = m;
			while (expensive[j])
				j++;
			vector<int> v;
			if (j != n)
			{
				v = ask(j);
				if (v[0] + v[1] < ecount)
				{
					l = j;
					expensive[j] = true;
					break;
				}
			}
			else
			{
				v.pb(ecount);
			}
			if (v[0] > upper_bound(vv.begin(), vv.end(), j) - vv.begin())
				r = m;
			else
				l = m;
		}
		vv.insert(lower_bound(vv.begin(), vv.end(), l), l);
	}
	for (int i = 0; i < n; i++)
	{
		if (expensive[i])
		{
			vector<int> v = ask(i);
			if (v[0] + v[1] == 0)
				return i;
		}
	}

	return -1;
}
int brute(int n)
{
	for (int i = 0; i < n; i++)
	{
		vector<int> v = ask(i);
		if (v[0] + v[1] == 0)
			return i;
	}
	return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:43:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |  while (vv.size() < ecount)
      |         ~~~~~~~~~~^~~~~~~~
prize.cpp:48:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |    int m = l+r>>1;
      |            ~^~
prize.cpp:33:6: warning: unused variable 's' [-Wunused-variable]
   33 |  int s = 0;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 208 KB Output is correct
2 Correct 5 ms 304 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 5 ms 208 KB Output is correct
8 Correct 2 ms 304 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 5 ms 208 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 5 ms 208 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 3 ms 304 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 4 ms 292 KB Output is correct
12 Correct 9 ms 296 KB Output is correct
13 Correct 8 ms 208 KB Output is correct
14 Correct 17 ms 208 KB Output is correct
15 Partially correct 29 ms 320 KB Partially correct - number of queries: 8023
16 Partially correct 65 ms 336 KB Partially correct - number of queries: 8737
17 Partially correct 51 ms 208 KB Partially correct - number of queries: 8354
18 Partially correct 71 ms 308 KB Partially correct - number of queries: 8812
19 Partially correct 42 ms 328 KB Partially correct - number of queries: 7845
20 Partially correct 43 ms 332 KB Partially correct - number of queries: 5674
21 Partially correct 50 ms 300 KB Partially correct - number of queries: 8488
22 Partially correct 41 ms 296 KB Partially correct - number of queries: 6291
23 Correct 2 ms 348 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Partially correct 63 ms 300 KB Partially correct - number of queries: 8615
26 Partially correct 50 ms 300 KB Partially correct - number of queries: 8595
27 Correct 4 ms 336 KB Output is correct
28 Partially correct 40 ms 208 KB Partially correct - number of queries: 8748
29 Partially correct 38 ms 332 KB Partially correct - number of queries: 7147
30 Partially correct 44 ms 332 KB Partially correct - number of queries: 8748
31 Partially correct 58 ms 292 KB Partially correct - number of queries: 8309
32 Correct 8 ms 344 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Partially correct 53 ms 304 KB Partially correct - number of queries: 8546
35 Correct 7 ms 304 KB Output is correct
36 Partially correct 32 ms 428 KB Partially correct - number of queries: 8397
37 Correct 10 ms 208 KB Output is correct
38 Correct 5 ms 208 KB Output is correct
39 Partially correct 49 ms 208 KB Partially correct - number of queries: 8514
40 Partially correct 48 ms 304 KB Partially correct - number of queries: 7541
41 Partially correct 64 ms 208 KB Partially correct - number of queries: 8650
42 Partially correct 55 ms 304 KB Partially correct - number of queries: 8650
43 Partially correct 45 ms 312 KB Partially correct - number of queries: 8310
44 Partially correct 70 ms 304 KB Partially correct - number of queries: 8543
45 Partially correct 63 ms 312 KB Partially correct - number of queries: 8540
46 Partially correct 33 ms 424 KB Partially correct - number of queries: 8301
47 Partially correct 71 ms 312 KB Partially correct - number of queries: 8532
48 Partially correct 51 ms 208 KB Partially correct - number of queries: 8697
49 Partially correct 76 ms 208 KB Partially correct - number of queries: 8340
50 Partially correct 56 ms 304 KB Partially correct - number of queries: 8823
51 Partially correct 66 ms 328 KB Partially correct - number of queries: 8463
52 Partially correct 68 ms 324 KB Partially correct - number of queries: 8372
53 Correct 6 ms 208 KB Output is correct
54 Partially correct 52 ms 296 KB Partially correct - number of queries: 8486
55 Partially correct 55 ms 208 KB Partially correct - number of queries: 8359
56 Partially correct 56 ms 296 KB Partially correct - number of queries: 8813
57 Partially correct 28 ms 328 KB Partially correct - number of queries: 8599
58 Partially correct 52 ms 308 KB Partially correct - number of queries: 8761
59 Partially correct 56 ms 296 KB Partially correct - number of queries: 8627
60 Partially correct 78 ms 312 KB Partially correct - number of queries: 8567
61 Correct 5 ms 208 KB Output is correct
62 Correct 4 ms 208 KB Output is correct
63 Correct 6 ms 308 KB Output is correct
64 Correct 3 ms 348 KB Output is correct
65 Correct 5 ms 256 KB Output is correct
66 Partially correct 22 ms 340 KB Partially correct - number of queries: 5387
67 Correct 18 ms 328 KB Output is correct
68 Correct 9 ms 384 KB Output is correct
69 Partially correct 46 ms 296 KB Partially correct - number of queries: 5370
70 Correct 31 ms 208 KB Output is correct
71 Partially correct 47 ms 344 KB Partially correct - number of queries: 9468
72 Correct 9 ms 208 KB Output is correct
73 Partially correct 56 ms 260 KB Partially correct - number of queries: 9335
74 Partially correct 35 ms 348 KB Partially correct - number of queries: 9392
75 Correct 5 ms 208 KB Output is correct
76 Partially correct 29 ms 348 KB Partially correct - number of queries: 8100
77 Partially correct 67 ms 208 KB Partially correct - number of queries: 8916
78 Correct 9 ms 208 KB Output is correct
79 Correct 38 ms 216 KB Output is correct
80 Partially correct 78 ms 304 KB Partially correct - number of queries: 8906
81 Partially correct 77 ms 292 KB Partially correct - number of queries: 8917
82 Partially correct 56 ms 308 KB Partially correct - number of queries: 8770
83 Correct 6 ms 208 KB Output is correct
84 Partially correct 52 ms 308 KB Partially correct - number of queries: 7318
85 Partially correct 61 ms 208 KB Partially correct - number of queries: 8882
86 Correct 7 ms 336 KB Output is correct
87 Correct 4 ms 208 KB Output is correct
88 Correct 7 ms 208 KB Output is correct
89 Correct 7 ms 208 KB Output is correct
90 Correct 4 ms 208 KB Output is correct
91 Correct 5 ms 208 KB Output is correct
92 Correct 7 ms 208 KB Output is correct
93 Correct 12 ms 308 KB Output is correct
94 Correct 12 ms 256 KB Output is correct
95 Correct 12 ms 328 KB Output is correct
96 Correct 11 ms 208 KB Output is correct
97 Correct 9 ms 308 KB Output is correct