제출 #708770

#제출 시각아이디문제언어결과실행 시간메모리
708770t6twotwo드문 곤충 (IOI22_insects)C++17
99.89 / 100
72 ms284 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int min_cardinality(int n) {
    vector<bool> in(n);
    for (int i = 0; i < n; i++) {
        move_inside(i);
        if (press_button() == 2) move_outside(i);
        else in[i] = 1;
    }
    int type = 0;
    vector<bool> blocked(n);
    for (int i = 0; i < n; i++) {
        if (in[i]) {
            type++;
            blocked[i] = 1;
        }
    }
    int lo = 0, hi = n / type - 1, add = 1;
    while (lo < hi) {
        int x = (lo + hi + 1) / 2, cnt = 0; 
        for (int i = 0; i < n; i++) {
            if (blocked[i]) continue;
            move_inside(i);
            if (press_button() == add + x + 1) move_outside(i);
            else in[i] = 1, cnt++;
        }
        for (int i = 0; i < n; i++) {
            if (blocked[i]) continue;
            if (in[i]) {
                if (cnt == x * type) {
                    blocked[i] = 1;
                } else {
                    in[i] = 0;
                    move_outside(i);
                }
            } else if (cnt != x * type) {
                blocked[i] = 1;
            }
        }
        if (cnt == x * type) lo = 0, hi -= x, add += x;
        else hi = min(x - 1, cnt / type);
    }
    return lo + add;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...