#include "prize.h"
#include <vector>
#include <algorithm>
using namespace std;
int m, res;
void solve(int l, int r, int num){
if(num == 0) return;
if(l > r) return;
int mid = (l+r)/2;
vector<int> resp = ask(mid);
if(resp[0]+resp[1] == 0){
res = mid;
return;
}
int b = mid;
while(resp[0]+resp[1] != m && b < r){
b++;
resp = ask(b);
if(resp[0]+resp[1] == 0){
res = mid;
return;
}
}
if(resp[0]+resp[1] == m){
solve(l, mid-1, resp[0]-(b-mid));
solve(b+1, r, resp[1]);
} else{
solve(l, mid-1, num);
}
return;
}
int find_best(int n) {
if(n <= 3000){
for(int i=0; i<n; i++){
vector<int> resp = ask(i);
if(resp[0]+resp[1] == 0) return i;
}
}
vector<int> resp;
for(int i=0; i<500; i++){
resp = ask(i);
if(resp[0]+resp[1] == 0) return i;
m = max(m, resp[0]+resp[1]);
}
solve(0, n-1, m);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
7 ms |
328 KB |
Output is correct |
3 |
Correct |
7 ms |
400 KB |
Output is correct |
4 |
Correct |
9 ms |
400 KB |
Output is correct |
5 |
Correct |
7 ms |
400 KB |
Output is correct |
6 |
Correct |
2 ms |
400 KB |
Output is correct |
7 |
Correct |
6 ms |
400 KB |
Output is correct |
8 |
Correct |
6 ms |
476 KB |
Output is correct |
9 |
Correct |
4 ms |
552 KB |
Output is correct |
10 |
Correct |
8 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
552 KB |
Output is correct |
2 |
Correct |
6 ms |
556 KB |
Output is correct |
3 |
Correct |
5 ms |
556 KB |
Output is correct |
4 |
Correct |
8 ms |
556 KB |
Output is correct |
5 |
Correct |
7 ms |
560 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
7 ms |
560 KB |
Output is correct |
8 |
Correct |
7 ms |
560 KB |
Output is correct |
9 |
Correct |
9 ms |
560 KB |
Output is correct |
10 |
Correct |
11 ms |
560 KB |
Output is correct |
11 |
Incorrect |
46 ms |
560 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |