This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2000;
int A[MAXN+10], B[MAXN+10], P[MAXN+10];
int min_cardinality(int N)
{
for(int i=0; i<N; i++) P[i]=i;
random_shuffle(P, P+N);
for(int i=0; i<N; i++)
{
move_inside(P[i]); A[i]=1;
if(press_button()>1)
{
move_outside(P[i]); A[i]=0;
}
}
int cnt=0;
for(int i=0; i<N; i++) cnt+=A[i];
for(int i=0; i<N; i++) if(A[i]) A[i]=0, B[i]=1;
if(cnt==1) return N;
if(cnt==2)
{
for(int i=0; i<N; i++) move_inside(P[i]);
return N-press_button();
}
int lo=1, hi=N/cnt+1;
int val=cnt;
while(lo+1<hi)
{
int mid=lo+hi>>1, t=val;
for(int i=0; i<N; i++)
{
if(t==mid*cnt) break;
if(B[i]) continue;
move_inside(P[i]); A[i]=1; t++;
if(press_button()>mid)
{
move_outside(P[i]); A[i]=0; t--;
}
}
if(t==mid*cnt)
{
lo=mid;
for(int i=0; i<N; i++) if(!B[i] && A[i]) B[i]=1, A[i]=0, val++;
}
else
{
hi=mid;
for(int i=0; i<N; i++) if(!B[i] && !A[i]) B[i]=2;
for(int i=0; i<N; i++) if(A[i]) move_outside(P[i]), A[i]=0;
}
}
return lo;
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:40:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid=lo+hi>>1, t=val;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |