#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
constexpr int NMAX = 200000;
constexpr int NORMIE_MAX = 475;
int lessLeft[NMAX];
int lessRight[NMAX];
int totalHigher = -1;
pair<int, int> query(int i) {
if (lessLeft[i] == -1) {
vector<int> ans = ask(i);
lessLeft[i] = ans[0];
lessRight[i] = ans[1];
}
return {lessLeft[i], lessRight[i]};
}
int higherThan(int i) {
auto [lx, ly] = query(i);
return lx + ly;
}
void findAllValuables(int i, int j, int valBefore, int valAfter, vector<int> &ans) {
// printf("FNV %d %d %d %d\n", i, j, valBefore, valAfter);
if (i > j) return;
else {
int k = (i + j) / 2;
int nonValBefore, nonValAfter;
for (nonValAfter = k; nonValAfter <= j && higherThan(nonValAfter) != totalHigher; ++nonValAfter) {
ans.push_back(nonValAfter);
}
for (nonValBefore = k; nonValBefore >= i && higherThan(nonValBefore) != totalHigher; --nonValBefore) {
ans.push_back(nonValBefore);
}
if (lessLeft[nonValBefore] != valBefore) {
findAllValuables(i, nonValBefore - 1, valBefore, lessRight[nonValBefore], ans);
}
if (lessRight[nonValAfter] != valAfter) {
findAllValuables(nonValAfter + 1, j, lessLeft[nonValAfter], valAfter, ans);
}
}
}
int find_best(int n) {
memset(lessLeft, -1, sizeof lessLeft);
memset(lessRight, -1, sizeof lessRight);
if (n <= NORMIE_MAX) {
for (int i = 0; i < n - 1; ++i) {
if (higherThan(i) == 0) return i;
}
}
for (int i = 0; i < NORMIE_MAX; ++i) {
totalHigher = max(totalHigher, higherThan(i));
}
int firstNonValuable = -1;
for (int i = 0; i < n; ++i) {
if (higherThan(i) == totalHigher) {
firstNonValuable = i;
break;
}
}
vector<int> vToCheck;
for (int i = 0; i < firstNonValuable; ++i) vToCheck.push_back(i);
findAllValuables(firstNonValuable + 1, n - 1, query(firstNonValuable).first, 0, vToCheck);
for (int i : vToCheck) {
if (higherThan(i) == 0) return i;
}
return 0;
}
Compilation message
prize.cpp: In function 'int higherThan(int)':
prize.cpp:23:7: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [lx, ly] = query(i);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1912 KB |
Output is correct |
2 |
Correct |
7 ms |
1912 KB |
Output is correct |
3 |
Correct |
8 ms |
1912 KB |
Output is correct |
4 |
Correct |
3 ms |
1904 KB |
Output is correct |
5 |
Correct |
6 ms |
1920 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
7 |
Correct |
5 ms |
1920 KB |
Output is correct |
8 |
Correct |
8 ms |
1920 KB |
Output is correct |
9 |
Correct |
8 ms |
1920 KB |
Output is correct |
10 |
Correct |
8 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1920 KB |
Output is correct |
2 |
Correct |
7 ms |
1912 KB |
Output is correct |
3 |
Correct |
8 ms |
1920 KB |
Output is correct |
4 |
Correct |
7 ms |
1912 KB |
Output is correct |
5 |
Correct |
9 ms |
1920 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
6 ms |
1920 KB |
Output is correct |
9 |
Correct |
7 ms |
1912 KB |
Output is correct |
10 |
Correct |
8 ms |
1920 KB |
Output is correct |
11 |
Correct |
17 ms |
1920 KB |
Output is correct |
12 |
Correct |
14 ms |
1920 KB |
Output is correct |
13 |
Correct |
13 ms |
1920 KB |
Output is correct |
14 |
Correct |
14 ms |
1920 KB |
Output is correct |
15 |
Correct |
38 ms |
1920 KB |
Output is correct |
16 |
Partially correct |
58 ms |
2044 KB |
Partially correct - number of queries: 5070 |
17 |
Partially correct |
62 ms |
1912 KB |
Partially correct - number of queries: 5081 |
18 |
Partially correct |
63 ms |
1920 KB |
Partially correct - number of queries: 5077 |
19 |
Correct |
57 ms |
2060 KB |
Output is correct |
20 |
Correct |
44 ms |
1920 KB |
Output is correct |
21 |
Partially correct |
41 ms |
2040 KB |
Partially correct - number of queries: 5065 |
22 |
Correct |
21 ms |
1936 KB |
Output is correct |
23 |
Correct |
9 ms |
1912 KB |
Output is correct |
24 |
Correct |
13 ms |
1912 KB |
Output is correct |
25 |
Correct |
64 ms |
1912 KB |
Output is correct |
26 |
Correct |
63 ms |
1920 KB |
Output is correct |
27 |
Correct |
6 ms |
1920 KB |
Output is correct |
28 |
Correct |
61 ms |
1912 KB |
Output is correct |
29 |
Correct |
34 ms |
1912 KB |
Output is correct |
30 |
Partially correct |
62 ms |
1912 KB |
Partially correct - number of queries: 5041 |
31 |
Partially correct |
41 ms |
1940 KB |
Partially correct - number of queries: 5064 |
32 |
Correct |
13 ms |
1912 KB |
Output is correct |
33 |
Correct |
2 ms |
1920 KB |
Output is correct |
34 |
Partially correct |
64 ms |
2040 KB |
Partially correct - number of queries: 5135 |
35 |
Correct |
9 ms |
1920 KB |
Output is correct |
36 |
Partially correct |
63 ms |
2040 KB |
Partially correct - number of queries: 5045 |
37 |
Correct |
6 ms |
1912 KB |
Output is correct |
38 |
Correct |
8 ms |
1920 KB |
Output is correct |
39 |
Partially correct |
40 ms |
2040 KB |
Partially correct - number of queries: 5052 |
40 |
Correct |
36 ms |
1912 KB |
Output is correct |
41 |
Partially correct |
57 ms |
2040 KB |
Partially correct - number of queries: 5087 |
42 |
Partially correct |
46 ms |
2040 KB |
Partially correct - number of queries: 5087 |
43 |
Correct |
40 ms |
1920 KB |
Output is correct |
44 |
Partially correct |
65 ms |
1936 KB |
Partially correct - number of queries: 5100 |
45 |
Correct |
39 ms |
1920 KB |
Output is correct |
46 |
Partially correct |
55 ms |
1940 KB |
Partially correct - number of queries: 5037 |
47 |
Correct |
39 ms |
1904 KB |
Output is correct |
48 |
Partially correct |
45 ms |
1912 KB |
Partially correct - number of queries: 5082 |
49 |
Partially correct |
42 ms |
1920 KB |
Partially correct - number of queries: 5055 |
50 |
Partially correct |
40 ms |
2168 KB |
Partially correct - number of queries: 5079 |
51 |
Partially correct |
40 ms |
1920 KB |
Partially correct - number of queries: 5009 |
52 |
Partially correct |
36 ms |
1920 KB |
Partially correct - number of queries: 5078 |
53 |
Correct |
7 ms |
1912 KB |
Output is correct |
54 |
Partially correct |
63 ms |
1920 KB |
Partially correct - number of queries: 5053 |
55 |
Partially correct |
60 ms |
2168 KB |
Partially correct - number of queries: 5075 |
56 |
Partially correct |
45 ms |
1920 KB |
Partially correct - number of queries: 5066 |
57 |
Partially correct |
63 ms |
1912 KB |
Partially correct - number of queries: 5019 |
58 |
Partially correct |
65 ms |
1920 KB |
Partially correct - number of queries: 5131 |
59 |
Partially correct |
27 ms |
1948 KB |
Partially correct - number of queries: 5080 |
60 |
Partially correct |
65 ms |
1912 KB |
Partially correct - number of queries: 5044 |
61 |
Correct |
9 ms |
1912 KB |
Output is correct |
62 |
Correct |
6 ms |
1920 KB |
Output is correct |
63 |
Correct |
9 ms |
1920 KB |
Output is correct |
64 |
Correct |
7 ms |
1920 KB |
Output is correct |
65 |
Correct |
4 ms |
1912 KB |
Output is correct |
66 |
Correct |
10 ms |
1920 KB |
Output is correct |
67 |
Correct |
10 ms |
1920 KB |
Output is correct |
68 |
Correct |
7 ms |
1920 KB |
Output is correct |
69 |
Correct |
13 ms |
1920 KB |
Output is correct |
70 |
Correct |
7 ms |
1912 KB |
Output is correct |
71 |
Partially correct |
48 ms |
1920 KB |
Partially correct - number of queries: 5233 |
72 |
Correct |
14 ms |
1920 KB |
Output is correct |
73 |
Partially correct |
71 ms |
1920 KB |
Partially correct - number of queries: 5170 |
74 |
Partially correct |
44 ms |
1920 KB |
Partially correct - number of queries: 5197 |
75 |
Correct |
6 ms |
1920 KB |
Output is correct |
76 |
Correct |
38 ms |
2040 KB |
Output is correct |
77 |
Partially correct |
46 ms |
1920 KB |
Partially correct - number of queries: 5198 |
78 |
Correct |
8 ms |
1920 KB |
Output is correct |
79 |
Correct |
16 ms |
1936 KB |
Output is correct |
80 |
Partially correct |
31 ms |
1972 KB |
Partially correct - number of queries: 5181 |
81 |
Partially correct |
72 ms |
1920 KB |
Partially correct - number of queries: 5194 |
82 |
Partially correct |
71 ms |
1920 KB |
Partially correct - number of queries: 5150 |
83 |
Correct |
9 ms |
1920 KB |
Output is correct |
84 |
Correct |
58 ms |
1920 KB |
Output is correct |
85 |
Partially correct |
73 ms |
2040 KB |
Partially correct - number of queries: 5221 |
86 |
Correct |
7 ms |
1920 KB |
Output is correct |
87 |
Correct |
7 ms |
1920 KB |
Output is correct |
88 |
Correct |
7 ms |
1920 KB |
Output is correct |
89 |
Correct |
7 ms |
1920 KB |
Output is correct |
90 |
Correct |
7 ms |
1920 KB |
Output is correct |
91 |
Correct |
4 ms |
1952 KB |
Output is correct |
92 |
Correct |
8 ms |
1920 KB |
Output is correct |
93 |
Correct |
10 ms |
1920 KB |
Output is correct |
94 |
Correct |
9 ms |
1920 KB |
Output is correct |
95 |
Correct |
12 ms |
1920 KB |
Output is correct |
96 |
Correct |
8 ms |
1920 KB |
Output is correct |
97 |
Correct |
6 ms |
1920 KB |
Output is correct |