#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define f first
#define s second
const int MAX_N = 2e5;
int ans[MAX_N][2];
bool found = false;
int pos;
pi q(int l){
if(ans[l][0]!=-1) return {ans[l][0], ans[l][1]};
else{
auto hold = ask(l);
ans[l][0] =hold[0];
ans[l][1] =hold[1];
return {ans[l][0], ans[l][1]};
// return {0,1};
}
}
void solve( int l, int r ) {
if(found) return;
int m = (l+r)/2;
pi res = q(m);
if(res.f ==0 && res.s==0){
pos = m;
found = true;
return;
}
if(res.f!=0){
solve(l,m);
}
if(res.s!=0){
solve(m+1,r);
}
}
int find_best( int n ) {
for( int i = 0; i < n; i++ )
ans[i][0] = ans[i][1] = -1;
solve( 0, n - 1 );
return pos;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1880 KB |
Output is correct |
3 |
Correct |
1 ms |
1880 KB |
Output is correct |
4 |
Correct |
1 ms |
1980 KB |
Output is correct |
5 |
Correct |
1 ms |
1880 KB |
Output is correct |
6 |
Correct |
2 ms |
1880 KB |
Output is correct |
7 |
Correct |
1 ms |
1880 KB |
Output is correct |
8 |
Correct |
1 ms |
1880 KB |
Output is correct |
9 |
Correct |
1 ms |
2132 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1880 KB |
Output is correct |
3 |
Correct |
1 ms |
1880 KB |
Output is correct |
4 |
Correct |
1 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1880 KB |
Output is correct |
6 |
Correct |
1 ms |
1880 KB |
Output is correct |
7 |
Correct |
1 ms |
2132 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
1 ms |
2136 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
11 |
Runtime error |
618 ms |
1048576 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |