#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
bool visited[maxn];
int find_best(int n) {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
srand(time(NULL));
if(n <= 10000) {
for(int i=1;i<=n;i++) {
vector<int>v = ask(i);
if(v[0] == v[1]) return i;
}
}
int fst = 0, lst = n-1;
for(int i=1;i<=4500;i++) {
int x = uniform_int_distribution<int>(0, n-1)(rng);
while(visited[x]) x = uniform_int_distribution<int>(0, n-1)(rng);
visited[x] = true;
vector<int>v = ask(x);
if(v[0] == v[1] && v[0] == 0) return x;
// looking for the last {0, 1}
// looking for the first {1, 0}
if(v[0] == 0) fst = max(fst, x);
else if(v[1] == 0) lst = min(lst, x);
}
if(fst > lst) {
while(true){
int br= 0;
}
}
for(int i=fst;i<=lst;i++) {
vector<int>v = ask(i);
if(v[0] == v[1] && v[0] == 0) return i;
}
return 0;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:41:17: warning: unused variable 'br' [-Wunused-variable]
int br= 0;
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
512 KB |
Output is correct |
2 |
Correct |
23 ms |
508 KB |
Output is correct |
3 |
Correct |
38 ms |
504 KB |
Output is correct |
4 |
Correct |
23 ms |
572 KB |
Output is correct |
5 |
Correct |
16 ms |
508 KB |
Output is correct |
6 |
Correct |
16 ms |
516 KB |
Output is correct |
7 |
Correct |
16 ms |
700 KB |
Output is correct |
8 |
Correct |
29 ms |
504 KB |
Output is correct |
9 |
Correct |
16 ms |
576 KB |
Output is correct |
10 |
Correct |
31 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
712 KB |
Output is correct |
2 |
Correct |
44 ms |
528 KB |
Output is correct |
3 |
Correct |
29 ms |
508 KB |
Output is correct |
4 |
Correct |
49 ms |
512 KB |
Output is correct |
5 |
Correct |
43 ms |
440 KB |
Output is correct |
6 |
Correct |
16 ms |
612 KB |
Output is correct |
7 |
Correct |
31 ms |
504 KB |
Output is correct |
8 |
Correct |
30 ms |
532 KB |
Output is correct |
9 |
Correct |
38 ms |
504 KB |
Output is correct |
10 |
Correct |
22 ms |
512 KB |
Output is correct |
11 |
Incorrect |
70 ms |
428 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |