#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){
vector<int> C = Ask(l);
if(C[0] + C[1] == 0) ans = l;
suf--;
return;
}
auto w = Ask(r);
if(w[1] == suf) return;
if(w[0] + w[1] == 0){
ans = r;
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 - 1);
if(w[1] < suf) suf--;
return;
}
Learn(l, mid - 1);
if(u[1] < suf) suf--;
if(ans != -1 || w[1] == suf) return;
Learn(mid + 1, r - 1);
if(w[1] < suf) suf--;
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);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
9 ms |
504 KB |
Output is correct |
4 |
Correct |
8 ms |
592 KB |
Output is correct |
5 |
Correct |
9 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
7 ms |
484 KB |
Output is correct |
8 |
Correct |
10 ms |
472 KB |
Output is correct |
9 |
Correct |
10 ms |
624 KB |
Output is correct |
10 |
Correct |
10 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
1120 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
9 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
9 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
592 KB |
Output is correct |
9 |
Correct |
9 ms |
336 KB |
Output is correct |
10 |
Correct |
8 ms |
336 KB |
Output is correct |
11 |
Incorrect |
193 ms |
1816 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |