#include <bits/stdc++.h>
#include "prize.h"
#define N 200050
using namespace std;
int n, v[N], maior, ans, raiz;
vector<int> dp[N];
vector<int> aski(int x)
{
if(!dp[x].empty()) return dp[x];
return dp[x] = ask(x);
}
#define f first
#define s second
typedef pair<int, int> pii;
vector<int> bucket[500];
int solve(int p, int en)
{
while(p <= en)
{
vector<int> aux = aski(p);
if(aux[0] + aux[1] == 0) return p;
int ini = p + 1, fim = en, mid;
if(aux[0] + aux[1] == maior)
{
while(fim >= ini)
{
mid = (ini + fim)/2;
vector<int> atual = aski(mid);
if(atual[0] + atual[1] == 0) return mid;
if(ini == fim) break;
if(atual[0] + atual[1] < maior) fim = mid;
else
{
if(aux[1] - atual[1] > 0) fim = mid - 1;
else ini = mid + 1;
}
}
p = ini + 1;
} else p++;
}
return -1;
}
int find_best(int n)
{
raiz = 500;
for(int i = 0; i < n; i ++ ) bucket[i/raiz].push_back(i);
for(int i = 0; i < raiz; i++)
{
vector<int> aux = aski(i);
if(aux[0] + aux[1] == 0) return i;
maior = max(maior, aux[0] + aux[1]);
}
for(int i = 0; i < 500; i++)
{
if(bucket[i].empty()) continue;
int a = bucket[i][0], b = bucket[i].back();
int ans = solve(a, b);
if(ans > -1) return ans;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
8288 KB |
Output is correct |
2 |
Correct |
16 ms |
8420 KB |
Output is correct |
3 |
Correct |
13 ms |
8420 KB |
Output is correct |
4 |
Correct |
0 ms |
8420 KB |
Output is correct |
5 |
Correct |
29 ms |
8420 KB |
Output is correct |
6 |
Correct |
6 ms |
8288 KB |
Output is correct |
7 |
Correct |
39 ms |
8420 KB |
Output is correct |
8 |
Correct |
6 ms |
8420 KB |
Output is correct |
9 |
Correct |
9 ms |
8420 KB |
Output is correct |
10 |
Correct |
33 ms |
8420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8288 KB |
Output is correct |
2 |
Correct |
13 ms |
8420 KB |
Output is correct |
3 |
Correct |
16 ms |
8420 KB |
Output is correct |
4 |
Correct |
33 ms |
8420 KB |
Output is correct |
5 |
Correct |
29 ms |
8420 KB |
Output is correct |
6 |
Correct |
3 ms |
8288 KB |
Output is correct |
7 |
Correct |
26 ms |
8420 KB |
Output is correct |
8 |
Correct |
6 ms |
8420 KB |
Output is correct |
9 |
Correct |
13 ms |
8420 KB |
Output is correct |
10 |
Correct |
26 ms |
8420 KB |
Output is correct |
11 |
Correct |
19 ms |
8420 KB |
Output is correct |
12 |
Correct |
3 ms |
8288 KB |
Output is correct |
13 |
Correct |
63 ms |
8420 KB |
Output is correct |
14 |
Correct |
9 ms |
7628 KB |
Output is correct |
15 |
Correct |
13 ms |
8420 KB |
Output is correct |
16 |
Partially correct |
43 ms |
8552 KB |
Partially correct - number of queries: 7033 |
17 |
Correct |
9 ms |
8288 KB |
Output is correct |
18 |
Partially correct |
49 ms |
8552 KB |
Partially correct - number of queries: 8387 |
19 |
Correct |
6 ms |
8288 KB |
Output is correct |
20 |
Correct |
9 ms |
8024 KB |
Output is correct |
21 |
Correct |
19 ms |
8420 KB |
Output is correct |
22 |
Correct |
3 ms |
8420 KB |
Output is correct |
23 |
Correct |
13 ms |
8288 KB |
Output is correct |
24 |
Correct |
3 ms |
8288 KB |
Output is correct |
25 |
Correct |
43 ms |
8420 KB |
Output is correct |
26 |
Correct |
19 ms |
8420 KB |
Output is correct |
27 |
Correct |
9 ms |
8420 KB |
Output is correct |
28 |
Partially correct |
46 ms |
8552 KB |
Partially correct - number of queries: 7973 |
29 |
Partially correct |
36 ms |
8552 KB |
Partially correct - number of queries: 6644 |
30 |
Partially correct |
76 ms |
8552 KB |
Partially correct - number of queries: 8368 |
31 |
Correct |
3 ms |
8288 KB |
Output is correct |
32 |
Correct |
13 ms |
8420 KB |
Output is correct |
33 |
Correct |
3 ms |
7496 KB |
Output is correct |
34 |
Correct |
26 ms |
8420 KB |
Output is correct |
35 |
Correct |
6 ms |
8420 KB |
Output is correct |
36 |
Correct |
13 ms |
8420 KB |
Output is correct |
37 |
Correct |
6 ms |
8420 KB |
Output is correct |
38 |
Correct |
6 ms |
8288 KB |
Output is correct |
39 |
Correct |
9 ms |
8420 KB |
Output is correct |
40 |
Partially correct |
49 ms |
8552 KB |
Partially correct - number of queries: 7591 |
41 |
Correct |
29 ms |
8420 KB |
Output is correct |
42 |
Correct |
23 ms |
8420 KB |
Output is correct |
43 |
Correct |
53 ms |
8420 KB |
Output is correct |
44 |
Correct |
19 ms |
8420 KB |
Output is correct |
45 |
Correct |
13 ms |
8420 KB |
Output is correct |
46 |
Correct |
9 ms |
8288 KB |
Output is correct |
47 |
Correct |
13 ms |
8420 KB |
Output is correct |
48 |
Partially correct |
56 ms |
8552 KB |
Partially correct - number of queries: 6112 |
49 |
Correct |
6 ms |
8288 KB |
Output is correct |
50 |
Partially correct |
33 ms |
8552 KB |
Partially correct - number of queries: 8383 |
51 |
Correct |
6 ms |
8420 KB |
Output is correct |
52 |
Correct |
0 ms |
8288 KB |
Output is correct |
53 |
Correct |
36 ms |
8420 KB |
Output is correct |
54 |
Correct |
19 ms |
8420 KB |
Output is correct |
55 |
Correct |
3 ms |
8288 KB |
Output is correct |
56 |
Partially correct |
23 ms |
8552 KB |
Partially correct - number of queries: 8370 |
57 |
Partially correct |
39 ms |
8552 KB |
Partially correct - number of queries: 6024 |
58 |
Partially correct |
29 ms |
8552 KB |
Partially correct - number of queries: 6121 |
59 |
Correct |
33 ms |
8420 KB |
Output is correct |
60 |
Correct |
53 ms |
8420 KB |
Output is correct |
61 |
Correct |
9 ms |
8420 KB |
Output is correct |
62 |
Correct |
3 ms |
8288 KB |
Output is correct |
63 |
Correct |
53 ms |
8420 KB |
Output is correct |
64 |
Correct |
13 ms |
8420 KB |
Output is correct |
65 |
Correct |
23 ms |
8420 KB |
Output is correct |
66 |
Correct |
33 ms |
8420 KB |
Output is correct |
67 |
Correct |
23 ms |
8420 KB |
Output is correct |
68 |
Correct |
6 ms |
8288 KB |
Output is correct |
69 |
Correct |
33 ms |
8420 KB |
Output is correct |
70 |
Correct |
13 ms |
8420 KB |
Output is correct |
71 |
Partially correct |
59 ms |
8552 KB |
Partially correct - number of queries: 8189 |
72 |
Correct |
39 ms |
8420 KB |
Output is correct |
73 |
Partially correct |
23 ms |
8552 KB |
Partially correct - number of queries: 8140 |
74 |
Partially correct |
66 ms |
8552 KB |
Partially correct - number of queries: 8161 |
75 |
Correct |
19 ms |
8420 KB |
Output is correct |
76 |
Partially correct |
33 ms |
8552 KB |
Partially correct - number of queries: 7681 |
77 |
Partially correct |
33 ms |
8552 KB |
Partially correct - number of queries: 8428 |
78 |
Correct |
23 ms |
8420 KB |
Output is correct |
79 |
Partially correct |
29 ms |
8552 KB |
Partially correct - number of queries: 6221 |
80 |
Partially correct |
33 ms |
8552 KB |
Partially correct - number of queries: 8438 |
81 |
Partially correct |
63 ms |
8552 KB |
Partially correct - number of queries: 8461 |
82 |
Partially correct |
26 ms |
8552 KB |
Partially correct - number of queries: 8369 |
83 |
Correct |
29 ms |
8420 KB |
Output is correct |
84 |
Partially correct |
33 ms |
8552 KB |
Partially correct - number of queries: 7716 |
85 |
Partially correct |
59 ms |
8552 KB |
Partially correct - number of queries: 8417 |
86 |
Correct |
16 ms |
8420 KB |
Output is correct |
87 |
Correct |
36 ms |
8420 KB |
Output is correct |
88 |
Correct |
23 ms |
8420 KB |
Output is correct |
89 |
Correct |
33 ms |
8420 KB |
Output is correct |
90 |
Correct |
16 ms |
8420 KB |
Output is correct |
91 |
Correct |
9 ms |
8420 KB |
Output is correct |
92 |
Correct |
26 ms |
8420 KB |
Output is correct |
93 |
Correct |
49 ms |
8420 KB |
Output is correct |
94 |
Correct |
23 ms |
8420 KB |
Output is correct |
95 |
Correct |
29 ms |
8420 KB |
Output is correct |
96 |
Correct |
3 ms |
8420 KB |
Output is correct |
97 |
Correct |
23 ms |
8420 KB |
Output is correct |