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>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 2005;
int n, D, step;
int vis[maxn];
int forb[maxn];
vector<ii> in;
int check(int x) {
for(int i = 0;i < n;i++) {
if(vis[i] || forb[i]) continue;
move_inside(i);
if(press_button() > x)
move_outside(i), forb[i] = 1;
else in.pb({i, step}), vis[i] = 1;
if((int)in.size() == x * D) return 1;
}
return 0;
}
int min_cardinality(int N) {
n = N, D = 0, step = 1;
for(int i = 0;i < n;i++) {
move_inside(i);
if(press_button() > 1)
move_outside(i);
else in.pb({i, step}), vis[i] = 1, D++;
}
int lo = 2, hi = n / D, ans = 1;
while(lo <= hi) {
step++;
int mid = (lo + hi) / 2;
int flag = check(mid);
if(flag) {
ans = mid, lo = mid + 1;
for(int i = 0;i < n;i++) forb[i] = 0;
} else {
hi = mid - 1;
while(in.back().y == step)
move_outside(in.back().x), vis[in.back().x] = 0, in.pop_back();
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |