Submission #69945

# Submission time Handle Problem Language Result Execution time Memory
69945 2018-08-22T05:56:13 Z Diuven The Big Prize (IOI17_prize) C++14
98.84 / 100
85 ms 2240 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MX=200010;
 
bool up[MX];
int L[MX], R[MX], sum, n, ans=-1;
 
void my_ask(int i){
	if(L[i]>=0) return;
	vi now=ask(i);
	L[i]=now[0], R[i]=now[1];
}
 
void search(int s, int e, int lc, int mc, int rc){
	if(s>e || mc<=0) return;
 
	int m=(s+e)/2;
 
	for(int i=m; i<=e; i++){
		my_ask(i);
		if(L[i]+R[i]==0){ ans=i; return; }
		if(L[i]+R[i]==sum){
			search(s,m-1, lc, L[i]-(i-m)-lc, R[i]+i-m);
			search(i+1,e, L[i], R[i]-rc, rc);
			return;
		}
	}
	for(int i=m; i>=s; i--){
		my_ask(i);
		if(L[i]+R[i]==0){ ans=i; return; }
		if(L[i]+R[i]==sum){
			search(s,i-1, lc, L[i]-lc, R[i]);
			return;
		}
	}
}
 
void solve(){
	int b=0;
	for(; b*b<=n; b++);
	vector<int> V;
    for(int ii=0; ii*b<n; ii++){
        int i=ii*b;
        my_ask(i); if(i+1<n) my_ask(i+1);
        sum=max({sum, L[i]+R[i], L[i+1]+R[i+1]});
    }
	V.push_back(0);
	for(int ii=0; ii*b<n; ii++){
		for(int j=ii*b; j<min(n, ii*b+b); j++){
			my_ask(j);
			if(L[j]+R[j]==sum){
				V.push_back(j);
				break;
			}
		}
	}
	V.push_back(n);
	for(int i=0; i<(int)V.size()-1; i++){
		int s=V[i], e=V[i+1];
		my_ask(s); if(e<n) my_ask(e);
		int l=L[s], r=0;
		if(e<n) r = R[e] + (L[e]+R[e]<sum);
		search(s,e-1,l,sum-l-r,r);
	}
}
 
int find_best(int _n){
	n=_n;
	for(int i=0; i<n; i++) L[i]=R[i]=-1;
	solve();
	assert(ans>=0 && L[ans]==0 && R[ans]==0);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1784 KB Output is correct
2 Correct 16 ms 1972 KB Output is correct
3 Correct 12 ms 1972 KB Output is correct
4 Correct 14 ms 1972 KB Output is correct
5 Correct 11 ms 2100 KB Output is correct
6 Correct 17 ms 2140 KB Output is correct
7 Correct 20 ms 2140 KB Output is correct
8 Correct 17 ms 2140 KB Output is correct
9 Correct 15 ms 2140 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2140 KB Output is correct
2 Correct 12 ms 2140 KB Output is correct
3 Correct 18 ms 2140 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 14 ms 2140 KB Output is correct
6 Correct 19 ms 2140 KB Output is correct
7 Correct 13 ms 2140 KB Output is correct
8 Correct 13 ms 2140 KB Output is correct
9 Correct 9 ms 2140 KB Output is correct
10 Correct 13 ms 2224 KB Output is correct
11 Correct 17 ms 2224 KB Output is correct
12 Correct 14 ms 2224 KB Output is correct
13 Correct 21 ms 2224 KB Output is correct
14 Correct 10 ms 2224 KB Output is correct
15 Correct 60 ms 2224 KB Output is correct
16 Correct 85 ms 2224 KB Output is correct
17 Correct 32 ms 2224 KB Output is correct
18 Correct 47 ms 2224 KB Output is correct
19 Correct 55 ms 2224 KB Output is correct
20 Correct 19 ms 2224 KB Output is correct
21 Correct 26 ms 2224 KB Output is correct
22 Correct 49 ms 2224 KB Output is correct
23 Correct 15 ms 2224 KB Output is correct
24 Correct 27 ms 2224 KB Output is correct
25 Correct 51 ms 2224 KB Output is correct
26 Correct 67 ms 2224 KB Output is correct
27 Correct 17 ms 2224 KB Output is correct
28 Correct 44 ms 2224 KB Output is correct
29 Correct 44 ms 2224 KB Output is correct
30 Correct 66 ms 2224 KB Output is correct
31 Correct 63 ms 2224 KB Output is correct
32 Correct 10 ms 2224 KB Output is correct
33 Correct 4 ms 2224 KB Output is correct
34 Correct 61 ms 2224 KB Output is correct
35 Correct 12 ms 2224 KB Output is correct
36 Correct 50 ms 2224 KB Output is correct
37 Correct 14 ms 2224 KB Output is correct
38 Correct 20 ms 2224 KB Output is correct
39 Correct 42 ms 2224 KB Output is correct
40 Correct 35 ms 2224 KB Output is correct
41 Correct 44 ms 2224 KB Output is correct
42 Correct 43 ms 2224 KB Output is correct
43 Correct 52 ms 2224 KB Output is correct
44 Correct 55 ms 2224 KB Output is correct
45 Correct 46 ms 2224 KB Output is correct
46 Correct 46 ms 2224 KB Output is correct
47 Correct 36 ms 2224 KB Output is correct
48 Correct 46 ms 2224 KB Output is correct
49 Correct 47 ms 2224 KB Output is correct
50 Correct 44 ms 2224 KB Output is correct
51 Correct 49 ms 2224 KB Output is correct
52 Correct 63 ms 2224 KB Output is correct
53 Correct 8 ms 2224 KB Output is correct
54 Correct 48 ms 2224 KB Output is correct
55 Correct 56 ms 2224 KB Output is correct
56 Correct 31 ms 2224 KB Output is correct
57 Correct 27 ms 2224 KB Output is correct
58 Correct 42 ms 2224 KB Output is correct
59 Correct 43 ms 2240 KB Output is correct
60 Correct 41 ms 2240 KB Output is correct
61 Correct 12 ms 2240 KB Output is correct
62 Correct 14 ms 2240 KB Output is correct
63 Correct 17 ms 2240 KB Output is correct
64 Correct 12 ms 2240 KB Output is correct
65 Correct 13 ms 2240 KB Output is correct
66 Correct 16 ms 2240 KB Output is correct
67 Correct 9 ms 2240 KB Output is correct
68 Correct 8 ms 2240 KB Output is correct
69 Correct 12 ms 2240 KB Output is correct
70 Correct 8 ms 2240 KB Output is correct
71 Partially correct 28 ms 2240 KB Partially correct - number of queries: 5116
72 Correct 13 ms 2240 KB Output is correct
73 Partially correct 66 ms 2240 KB Partially correct - number of queries: 5060
74 Partially correct 45 ms 2240 KB Partially correct - number of queries: 5084
75 Correct 15 ms 2240 KB Output is correct
76 Correct 55 ms 2240 KB Output is correct
77 Correct 62 ms 2240 KB Output is correct
78 Correct 16 ms 2240 KB Output is correct
79 Correct 20 ms 2240 KB Output is correct
80 Correct 62 ms 2240 KB Output is correct
81 Correct 57 ms 2240 KB Output is correct
82 Correct 37 ms 2240 KB Output is correct
83 Correct 11 ms 2240 KB Output is correct
84 Correct 43 ms 2240 KB Output is correct
85 Correct 59 ms 2240 KB Output is correct
86 Correct 32 ms 2240 KB Output is correct
87 Correct 13 ms 2240 KB Output is correct
88 Correct 33 ms 2240 KB Output is correct
89 Correct 35 ms 2240 KB Output is correct
90 Correct 11 ms 2240 KB Output is correct
91 Correct 18 ms 2240 KB Output is correct
92 Correct 36 ms 2240 KB Output is correct
93 Correct 30 ms 2240 KB Output is correct
94 Correct 37 ms 2240 KB Output is correct
95 Correct 48 ms 2240 KB Output is correct
96 Correct 33 ms 2240 KB Output is correct
97 Correct 43 ms 2240 KB Output is correct