Submission #429108

# Submission time Handle Problem Language Result Execution time Memory
429108 2021-06-15T17:28:30 Z vanic The Big Prize (IOI17_prize) C++14
97.06 / 100
105 ms 516 KB
#include "prize.h"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <set>
#include <unistd.h>
#include <cassert>

using namespace std;

const int maxn=2e5+5;
const int cap=1000;

int sum;
bool asked[maxn];
int uk;

int nadji(int L, int D, int vall, int vald){
	int mid=(L+D)/2;
	vector < int > v={-1, -1};
	while(mid<D && v[0]+v[1]!=sum){
		if(!asked[mid]){
			uk++;
			v=ask(mid);
			asked[mid]=1;
			if(!v[0] && !v[1]){
				return mid;
			}
		}
		mid++;
	}
	if(v[0]+v[1]!=sum){
		mid=(L+D)/2;
		while(mid>=L && v[0]+v[1]!=sum){
			if(!asked[mid]){
				uk++;
				v=ask(mid);
				asked[mid]=1;
				if(!v[0] && !v[1]){
					return mid;
				}
			}
			mid--;
		}
		if(v[0]+v[1]!=sum){
			return -1;
		}
		uk--;
		mid++;
	}
	else{
		uk--;
		mid--;
	}
	assert(uk<cap);
	int br=-1;
	if(v[0]-vall){
		br=nadji(L, mid, vall, v[1]);
		if(br!=-1){
			return br;
		}
	}
	if(v[1]-vald){
		br=nadji(mid+1, D, v[0], vald);
	}
	return br;
}

set < int > svi;
set < int > jaki;

int find_best(int n){
	srand(time(NULL));
	vector < int > v;
	int pos;
	if(n>5000){
		for(int i=0; i<447; i++){
			do{
				pos=rand()%n;
			}while(svi.find(pos)!=svi.end());
			v=ask(pos);
			svi.insert(pos);
			if(!v[0] && !v[1]){
				return pos;
			}
			if(v[0]+v[1]==sum){
				jaki.insert(pos);
			}
			else if(v[0]+v[1]>sum){
				jaki.clear();
				jaki.insert(pos);
				sum=v[0]+v[1];
			}
		}
		while(!jaki.empty()){
			svi.erase(*jaki.begin());
			jaki.erase(jaki.begin());
		}
		while(!svi.empty()){
			asked[*svi.begin()]=1;
			svi.erase(svi.begin());
		}
		int a=nadji(0, n, 0, 0);
		assert(a!=-1);
		return a;
	}
	else{
		for(int i=0; i<n; i++){
			v=ask(i);
			if(!v[0] && !v[1]){
				return i;
			}
		}
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:77:17: warning: control reaches end of non-void function [-Wreturn-type]
   77 |  vector < int > v;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 300 KB Output is correct
2 Correct 9 ms 288 KB Output is correct
3 Correct 4 ms 300 KB Output is correct
4 Correct 5 ms 280 KB Output is correct
5 Correct 8 ms 264 KB Output is correct
6 Correct 8 ms 284 KB Output is correct
7 Correct 5 ms 296 KB Output is correct
8 Correct 7 ms 308 KB Output is correct
9 Correct 6 ms 328 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 316 KB Output is correct
2 Correct 5 ms 292 KB Output is correct
3 Correct 4 ms 280 KB Output is correct
4 Correct 7 ms 296 KB Output is correct
5 Correct 5 ms 312 KB Output is correct
6 Correct 7 ms 400 KB Output is correct
7 Correct 9 ms 284 KB Output is correct
8 Correct 3 ms 328 KB Output is correct
9 Correct 5 ms 296 KB Output is correct
10 Correct 7 ms 324 KB Output is correct
11 Correct 12 ms 412 KB Output is correct
12 Correct 5 ms 272 KB Output is correct
13 Correct 16 ms 400 KB Output is correct
14 Correct 10 ms 320 KB Output is correct
15 Correct 14 ms 352 KB Output is correct
16 Correct 50 ms 372 KB Output is correct
17 Correct 10 ms 284 KB Output is correct
18 Partially correct 62 ms 464 KB Partially correct - number of queries: 5215
19 Correct 8 ms 284 KB Output is correct
20 Correct 29 ms 352 KB Output is correct
21 Correct 24 ms 268 KB Output is correct
22 Correct 10 ms 348 KB Output is correct
23 Correct 8 ms 320 KB Output is correct
24 Correct 8 ms 288 KB Output is correct
25 Correct 43 ms 404 KB Output is correct
26 Correct 39 ms 420 KB Output is correct
27 Correct 7 ms 320 KB Output is correct
28 Correct 41 ms 416 KB Output is correct
29 Correct 51 ms 440 KB Output is correct
30 Partially correct 67 ms 460 KB Partially correct - number of queries: 5179
31 Correct 8 ms 288 KB Output is correct
32 Correct 9 ms 416 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 33 ms 280 KB Output is correct
35 Correct 10 ms 404 KB Output is correct
36 Correct 18 ms 292 KB Output is correct
37 Correct 7 ms 288 KB Output is correct
38 Correct 7 ms 328 KB Output is correct
39 Correct 38 ms 292 KB Output is correct
40 Correct 60 ms 452 KB Output is correct
41 Correct 42 ms 448 KB Output is correct
42 Correct 48 ms 428 KB Output is correct
43 Correct 41 ms 408 KB Output is correct
44 Correct 39 ms 332 KB Output is correct
45 Correct 22 ms 348 KB Output is correct
46 Correct 8 ms 296 KB Output is correct
47 Correct 23 ms 344 KB Output is correct
48 Correct 34 ms 424 KB Output is correct
49 Correct 11 ms 284 KB Output is correct
50 Partially correct 41 ms 440 KB Partially correct - number of queries: 5207
51 Correct 22 ms 404 KB Output is correct
52 Correct 10 ms 292 KB Output is correct
53 Correct 9 ms 408 KB Output is correct
54 Correct 31 ms 416 KB Output is correct
55 Correct 5 ms 296 KB Output is correct
56 Partially correct 59 ms 516 KB Partially correct - number of queries: 5214
57 Correct 58 ms 400 KB Output is correct
58 Correct 41 ms 416 KB Output is correct
59 Correct 57 ms 404 KB Output is correct
60 Correct 29 ms 404 KB Output is correct
61 Correct 11 ms 408 KB Output is correct
62 Correct 6 ms 296 KB Output is correct
63 Correct 10 ms 408 KB Output is correct
64 Correct 9 ms 312 KB Output is correct
65 Correct 5 ms 272 KB Output is correct
66 Correct 15 ms 288 KB Output is correct
67 Correct 11 ms 292 KB Output is correct
68 Correct 5 ms 284 KB Output is correct
69 Correct 15 ms 284 KB Output is correct
70 Correct 13 ms 328 KB Output is correct
71 Partially correct 64 ms 500 KB Partially correct - number of queries: 5198
72 Correct 7 ms 456 KB Output is correct
73 Partially correct 59 ms 420 KB Partially correct - number of queries: 5129
74 Partially correct 27 ms 508 KB Partially correct - number of queries: 5155
75 Correct 9 ms 328 KB Output is correct
76 Correct 57 ms 504 KB Output is correct
77 Partially correct 105 ms 512 KB Partially correct - number of queries: 5287
78 Correct 15 ms 376 KB Output is correct
79 Correct 37 ms 412 KB Output is correct
80 Partially correct 38 ms 408 KB Partially correct - number of queries: 5280
81 Partially correct 65 ms 512 KB Partially correct - number of queries: 5280
82 Partially correct 51 ms 444 KB Partially correct - number of queries: 5284
83 Correct 5 ms 420 KB Output is correct
84 Correct 41 ms 504 KB Output is correct
85 Partially correct 43 ms 500 KB Partially correct - number of queries: 5294
86 Correct 43 ms 420 KB Output is correct
87 Correct 17 ms 424 KB Output is correct
88 Correct 56 ms 444 KB Output is correct
89 Correct 27 ms 456 KB Output is correct
90 Correct 7 ms 328 KB Output is correct
91 Correct 45 ms 456 KB Output is correct
92 Correct 13 ms 456 KB Output is correct
93 Correct 59 ms 464 KB Output is correct
94 Correct 77 ms 444 KB Output is correct
95 Correct 48 ms 456 KB Output is correct
96 Correct 39 ms 456 KB Output is correct
97 Correct 35 ms 456 KB Output is correct