#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> nw;
int a[] = {475, 27, 5, 1};
int mx;
set<int> s;
int ans = -1;
void bin(int l, int r, int lx, int rx){
if(ans != -1) return;
if(v.size() == mx) return;
if(l == r){
nw.push_back(v[l]); return;
}
int mid = (l + r) / 2;
vector<int> rep = ask(v[mid]); //
s.insert(v[mid]);
if(rep[0] + rep[1] == 0){
ans = v[mid];
return;
}
int curr = mid;
while(rep[0] + rep[1] != mx && curr > l){
nw.push_back(v[curr]);
curr--;
rep = ask(v[curr]); //
s.insert(v[curr]);
if(rep[0] + rep[1] == 0){
ans = v[curr];
return;
}
}
if(rep[0] + rep[1] != mx) nw.push_back(v[curr]);
if(lx + rep[1] < mx && l < curr) bin(l, curr - 1, lx, rep[1]);
curr = mid;
while(rep[0] + rep[1] != mx && curr < r){
nw.push_back(v[curr]);
curr++;
rep = ask(v[curr]); //
s.insert(v[curr]);
if(rep[0] + rep[1] == 0){
ans = v[curr];
return;
}
}
if(rep[0] + rep[1] != mx) nw.push_back(v[curr]);
if(rx + rep[0] < mx && r > curr) bin(mid + 1, r, rep[0], rx);
}
int find_best(int n) {
v.resize(n);
for(int i = 0; i < n; i++){
v[i] = i;
}
int curr = 0;
int t = 0;
while(v.size() > 1 && t < 1){
mx = 0;
map<int, int> mp;
int lst = 0;
for(int i = 0; i < a[curr] && i < v.size(); i++){
vector<int> rep = ask (v[i]); //
mx = max(mx, rep[0] + rep[1]);
mp[rep[0] + rep[1]]++;
int m = max(0, mx - 30);
long long int sum = m * m;
sum *= sum;
lst = i + 1;
if(rep[0] + rep[1] == 0) return v[i];
if(sum >= n) break;
}
int total = 0;
for(auto p : mp){
if(p.first == mx) break;
total += p.second;
}
bin(lst, v.size() - 1, total, 0);
if(ans != -1) return ans;
curr++;
v = nw;
sort(v.begin(), v.end());
nw.clear();
t++;
}
for(int x : v){
if(s.count(x)) continue;
else{
vector<int> rep = ask(x);
if(rep[0] + rep[1] == 0) return x;
}
}
}
Compilation message
prize.cpp: In function 'void bin(int, int, int, int)':
prize.cpp:15:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | if(v.size() == mx) return;
| ~~~~~~~~~^~~~~
prize.cpp: In function 'int find_best(int)':
prize.cpp:66:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i = 0; i < a[curr] && i < v.size(); i++){
| ~~^~~~~~~~~~
prize.cpp:97:1: warning: control reaches end of non-void function [-Wreturn-type]
97 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1052 KB |
Output is correct |
2 |
Correct |
4 ms |
1060 KB |
Output is correct |
3 |
Correct |
3 ms |
1036 KB |
Output is correct |
4 |
Correct |
4 ms |
1056 KB |
Output is correct |
5 |
Correct |
3 ms |
1056 KB |
Output is correct |
6 |
Correct |
1 ms |
976 KB |
Output is correct |
7 |
Correct |
4 ms |
1092 KB |
Output is correct |
8 |
Correct |
3 ms |
1052 KB |
Output is correct |
9 |
Correct |
8 ms |
976 KB |
Output is correct |
10 |
Correct |
3 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1060 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
3 ms |
1104 KB |
Output is correct |
4 |
Correct |
3 ms |
976 KB |
Output is correct |
5 |
Correct |
3 ms |
1096 KB |
Output is correct |
6 |
Correct |
1 ms |
1056 KB |
Output is correct |
7 |
Correct |
5 ms |
1040 KB |
Output is correct |
8 |
Correct |
5 ms |
1056 KB |
Output is correct |
9 |
Correct |
4 ms |
976 KB |
Output is correct |
10 |
Correct |
4 ms |
976 KB |
Output is correct |
11 |
Correct |
7 ms |
1056 KB |
Output is correct |
12 |
Correct |
6 ms |
976 KB |
Output is correct |
13 |
Correct |
10 ms |
1092 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
7 ms |
1084 KB |
Output is correct |
16 |
Correct |
50 ms |
1184 KB |
Output is correct |
17 |
Correct |
1 ms |
968 KB |
Output is correct |
18 |
Correct |
46 ms |
1208 KB |
Output is correct |
19 |
Correct |
1 ms |
1052 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
29 ms |
1220 KB |
Output is correct |
22 |
Correct |
4 ms |
1056 KB |
Output is correct |
23 |
Correct |
4 ms |
1100 KB |
Output is correct |
24 |
Correct |
7 ms |
1060 KB |
Output is correct |
25 |
Correct |
23 ms |
1140 KB |
Output is correct |
26 |
Correct |
36 ms |
1180 KB |
Output is correct |
27 |
Correct |
7 ms |
976 KB |
Output is correct |
28 |
Correct |
38 ms |
1244 KB |
Output is correct |
29 |
Correct |
25 ms |
1188 KB |
Output is correct |
30 |
Correct |
26 ms |
1296 KB |
Output is correct |
31 |
Correct |
40 ms |
1508 KB |
Output is correct |
32 |
Correct |
8 ms |
1084 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
42 ms |
1208 KB |
Output is correct |
35 |
Correct |
6 ms |
1060 KB |
Output is correct |
36 |
Correct |
11 ms |
1108 KB |
Output is correct |
37 |
Correct |
8 ms |
1048 KB |
Output is correct |
38 |
Correct |
5 ms |
1096 KB |
Output is correct |
39 |
Correct |
18 ms |
1160 KB |
Output is correct |
40 |
Correct |
39 ms |
1212 KB |
Output is correct |
41 |
Correct |
28 ms |
1104 KB |
Output is correct |
42 |
Correct |
23 ms |
1160 KB |
Output is correct |
43 |
Correct |
47 ms |
1288 KB |
Output is correct |
44 |
Correct |
14 ms |
1052 KB |
Output is correct |
45 |
Correct |
11 ms |
1104 KB |
Output is correct |
46 |
Correct |
1 ms |
1060 KB |
Output is correct |
47 |
Correct |
20 ms |
1152 KB |
Output is correct |
48 |
Correct |
26 ms |
1308 KB |
Output is correct |
49 |
Correct |
40 ms |
1176 KB |
Output is correct |
50 |
Correct |
23 ms |
1292 KB |
Output is correct |
51 |
Correct |
18 ms |
1112 KB |
Output is correct |
52 |
Correct |
1 ms |
1056 KB |
Output is correct |
53 |
Correct |
5 ms |
1056 KB |
Output is correct |
54 |
Correct |
40 ms |
1180 KB |
Output is correct |
55 |
Correct |
1 ms |
1092 KB |
Output is correct |
56 |
Correct |
60 ms |
1232 KB |
Output is correct |
57 |
Correct |
38 ms |
1364 KB |
Output is correct |
58 |
Correct |
28 ms |
1128 KB |
Output is correct |
59 |
Correct |
23 ms |
1080 KB |
Output is correct |
60 |
Correct |
19 ms |
1144 KB |
Output is correct |
61 |
Correct |
5 ms |
1052 KB |
Output is correct |
62 |
Correct |
6 ms |
1048 KB |
Output is correct |
63 |
Correct |
6 ms |
976 KB |
Output is correct |
64 |
Correct |
5 ms |
976 KB |
Output is correct |
65 |
Correct |
5 ms |
1056 KB |
Output is correct |
66 |
Correct |
3 ms |
1096 KB |
Output is correct |
67 |
Correct |
2 ms |
1088 KB |
Output is correct |
68 |
Correct |
4 ms |
976 KB |
Output is correct |
69 |
Correct |
5 ms |
1104 KB |
Output is correct |
70 |
Correct |
1 ms |
1060 KB |
Output is correct |
71 |
Correct |
44 ms |
1264 KB |
Output is correct |
72 |
Correct |
9 ms |
1104 KB |
Output is correct |
73 |
Correct |
37 ms |
1324 KB |
Output is correct |
74 |
Correct |
39 ms |
1260 KB |
Output is correct |
75 |
Correct |
7 ms |
1100 KB |
Output is correct |
76 |
Correct |
33 ms |
1200 KB |
Output is correct |
77 |
Correct |
29 ms |
1248 KB |
Output is correct |
78 |
Correct |
7 ms |
1104 KB |
Output is correct |
79 |
Correct |
20 ms |
1124 KB |
Output is correct |
80 |
Correct |
64 ms |
1224 KB |
Output is correct |
81 |
Correct |
41 ms |
1352 KB |
Output is correct |
82 |
Correct |
42 ms |
1248 KB |
Output is correct |
83 |
Correct |
7 ms |
1096 KB |
Output is correct |
84 |
Correct |
40 ms |
1156 KB |
Output is correct |
85 |
Correct |
26 ms |
1356 KB |
Output is correct |
86 |
Correct |
5 ms |
976 KB |
Output is correct |
87 |
Correct |
7 ms |
1096 KB |
Output is correct |
88 |
Correct |
5 ms |
976 KB |
Output is correct |
89 |
Correct |
6 ms |
976 KB |
Output is correct |
90 |
Correct |
5 ms |
976 KB |
Output is correct |
91 |
Correct |
3 ms |
1064 KB |
Output is correct |
92 |
Correct |
5 ms |
1124 KB |
Output is correct |
93 |
Correct |
10 ms |
1104 KB |
Output is correct |
94 |
Correct |
10 ms |
1104 KB |
Output is correct |
95 |
Correct |
7 ms |
1104 KB |
Output is correct |
96 |
Correct |
9 ms |
976 KB |
Output is correct |
97 |
Correct |
6 ms |
1100 KB |
Output is correct |