#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int B = 500;
int find_best(int n){
vector <vector<int>> dp(n);
auto f = [&](int j){
if ( dp[j].empty() ){
dp[j] = ask(j);
}
return dp[j];
};
for ( int i = 0; i < n; i++ ){
int opt = -1, k = -1;
vector <int> cc;
for ( int j = i; j < min(n, i + B); j++ ){
auto c = f(j); int x = c[0] + c[1];
if ( x == 0 ){
return j;
}
if ( chmax(opt, x) || opt == x ){
k = j; cc = c;
}
}
int l = k, r = n;
while ( l + 1 < r ){
int m = (l + r) / 2;
if ( f(m) != cc ){
r = m;
} else l = m;
}
i = max(i + B - 1, l);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
4 ms |
4952 KB |
Output is correct |
4 |
Correct |
3 ms |
4952 KB |
Output is correct |
5 |
Correct |
4 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
4 ms |
4952 KB |
Output is correct |
8 |
Correct |
4 ms |
4952 KB |
Output is correct |
9 |
Correct |
4 ms |
5208 KB |
Output is correct |
10 |
Correct |
3 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
4952 KB |
Output is correct |
4 |
Correct |
4 ms |
4952 KB |
Output is correct |
5 |
Correct |
4 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
4 ms |
4952 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
4952 KB |
Output is correct |
11 |
Partially correct |
40 ms |
5800 KB |
Partially correct - number of queries: 7676 |
12 |
Correct |
3 ms |
4952 KB |
Output is correct |
13 |
Incorrect |
44 ms |
5720 KB |
Incorrect |
14 |
Halted |
0 ms |
0 KB |
- |