제출 #799730

#제출 시각아이디문제언어결과실행 시간메모리
799730rnl42Rarest Insects (IOI22_insects)C++17
99.76 / 100
54 ms420 KiB
#include "insects.h"
#include <vector>
#include <iostream>
#include <random>
#include <algorithm>
#include <numeric>
using namespace std;

int N, W;
vector<bool> deleted;
int remaining;

int get_width() {
    int ret = 0;
    for (int i = 0; i < N; i++) {
        move_inside(i);
        if (press_button() >= 2) {
            move_outside(i);
        } else {
            deleted[i] = true;
            ret++;
        }
    }
    return ret;
}

int min_cardinality(int _N) {
    N = _N;
    deleted.resize(N);
    W = get_width();

    remaining = N-W;
    int mini = 1, maxi = N/W;
    int minh = 1, maxh = N-W+1;
    if (W == 1) mini = N;
    vector<int> order(N);
    mt19937 rng(42);
    while (mini != maxi) {
        int mid = mini+1 == maxi ? (mini+maxi+1)>>1 : ((mini+maxi+(rng()&1))>>1);
        vector<int> in_machine;
        vector<int> out_machine;
        for (int i = 0; i < N; i++) {
            if (!deleted[i]) {
                move_inside(i);
                if (press_button() > mid) {
                    move_outside(i);
                    out_machine.push_back(i);
                } else {
                    in_machine.push_back(i);
                }
            }
        }
        if ((int)in_machine.size() == W*(mid-minh)) {
            for (int i : in_machine) {
                deleted[i] = true;
                remaining--;
            }
            mini = mid;
            minh = mid;
        } else {
            for (int i : out_machine) {
                deleted[i] = true;
                remaining--;
            }
            for (int i : in_machine) {
                move_outside(i);
            }
            maxi = mid-1;
            maxh = mid;
        }
    }
    return mini;
}

컴파일 시 표준 에러 (stderr) 메시지

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:34:19: warning: variable 'maxh' set but not used [-Wunused-but-set-variable]
   34 |     int minh = 1, maxh = N-W+1;
      |                   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...