#include "bits/stdc++.h"
#include "prize.h"
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
const int BL = 10000;
int suf = -1, ans = -1;
map<int,vector<int>> dp;
vector<bool> mark;
vector<int> Ask(int i){
if( dp.count(i) ) return dp[i];
return dp[i] = ask(i);
}
void Learn(int l,int r){
if(l > r || ans != -1) return;
if(l == r){
mark[l] = 1;
suf--;
return;
}
int mid = (l + r) / 2;
auto u = Ask(mid);
if(u[0] + u[1] == 0){
ans = mid;
return;
}
if(u[1] == suf){
Learn(mid + 1, r);
return;
}
Learn(l, mid - 1);
if(u[1] < suf) suf--;
if(ans != -1) return;
Learn(mid + 1, r);
return;
}
int find_best(int n){
mark.assign(n,0);
int art = 0, i = 0, mx = -1;
for(; i <= 475; i++){
if(art == 5) break;
vector<int> x = Ask(i);
if(x[0] + x[1] == 0) return i;
if(x[0] + x[1] > mx) art++;
if(x[0] + x[1] >= mx){
mx = x[0] + x[1];
suf = x[1];
}
else suf--;
}
Learn(i, n - 1);
if(ans != -1) return ans;
for(auto x : dp) if(x.second[0] + x.second[1] == 0) return x.first;
for(i = 0; i < n; i++){
if(mark[i] == 0) continue;
vector<int> Cand = Ask(i);
if(Cand[0] + Cand[1] == 0) return i;
}
assert(0);
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
336 KB |
Output is correct |
2 |
Correct |
8 ms |
612 KB |
Output is correct |
3 |
Correct |
8 ms |
592 KB |
Output is correct |
4 |
Correct |
9 ms |
504 KB |
Output is correct |
5 |
Correct |
10 ms |
496 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
9 ms |
996 KB |
Output is correct |
8 |
Correct |
10 ms |
848 KB |
Output is correct |
9 |
Correct |
10 ms |
336 KB |
Output is correct |
10 |
Correct |
10 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
336 KB |
Output is correct |
2 |
Correct |
10 ms |
336 KB |
Output is correct |
3 |
Correct |
7 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
720 KB |
Output is correct |
5 |
Correct |
9 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
8 ms |
504 KB |
Output is correct |
9 |
Correct |
8 ms |
336 KB |
Output is correct |
10 |
Correct |
9 ms |
336 KB |
Output is correct |
11 |
Incorrect |
206 ms |
1572 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |