제출 #628903

#제출 시각아이디문제언어결과실행 시간메모리
628903dqhungdl드문 곤충 (IOI22_insects)C++17
47.50 / 100
213 ms296 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

int diff = 0;
vector<bool> mark;

void countDiff(int N) {
    for (int i = 0; i < N; i++) {
        move_inside(i);
        if (press_button() == 1) {
            diff++;
            mark[i] = true;
        } else
            move_outside(i);
    }
}

bool check(int lim, int N) {
    for (int i = 0; i < N; i++)
        if (mark[i]) {
            mark[i] = false;
            move_outside(i);
        }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        move_inside(i);
        if (press_button() > lim)
            move_outside(i);
        else {
            cnt++;
            mark[i] = true;
        }
    }
    return cnt < lim * diff;
}

int min_cardinality(int N) {
    mark.resize(N);
    countDiff(N);
    int l = 2, r = N / diff, rs = 1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid, N))
            r = mid - 1;
        else {
            rs = mid;
            l = mid + 1;
        }
    }
    return rs;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...