Submission
Status:
(PPPPP)
Score: 100
User: Namkhing
Problemset: Ice cream
Language: cpp
Time: 0.008 second
Submitted On: 2025-04-23 18:28:51
#include "ice_cream.h"
#include <bits/stdc++.h>
using namespace std;
const int seed = 1;
const int inf = 1e9;
const int N = 1510;
int n, a[N], dp[N];
int guess(int N) {
// write your solution here
srand(seed);
n = N;
for (int i = 2; i <= n; i++) {
if (dp[i]) continue;
dp[i] = inf;
for (int j = 1; j < i; j++) {
int val = max(dp[j] + 2, dp[i-j] + 1);
if (dp[i] > val) dp[i] = val, a[i] = j;
}
}
int l = 1, r = n;
while (l < r) {
int sz = r - l + 1;
int opt = a[sz];
int b = l + opt;
int e = r - opt;
int x = rand() & 1;
if (x) {
bool f = ask(l, b - 1);
if (f) r = b - 1;
else l = b;
}
else {
bool f = ask(e + 1, r);
if (f) l = e + 1;
else r = e;
}
}
return l;
}