답안 #634191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634191 2022-08-24T05:03:39 Z spacewalker 드문 곤충 (IOI22_insects) C++17
99.79 / 100
62 ms 532 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

int ceil(int n, int r) {
    return n/r + n%r;
}

// Get an array of insects, such that all their types are distinct
// The representatives are left inside the machine
vector<int> getRepresentatives(int N) {
    vector<int> inMachine;
    for (int i = 0; i < N; ++i) {
        move_inside(i);
        if (press_button() > 1) {
            move_outside(i);
        } else {
            inMachine.push_back(i);
        }
    }
    return inMachine;
}

// find the max k such that all types have at least >= k insects
// in a query, we can check if all types have at least >= k' insects

int getAllLowerBound(vector<int> ids, int B, int answerMax, int machineBase) {
    if (answerMax == 0 || ids.size() < B) return 0; // base case
    /*
        printf("GALB([");
        for (int v : ids) printf("%d ", v);
        printf("], %d, %d)\n",B, answerMax);
    */
    // set mid such that the success case eliminates around N/2 elements
    int mid = ids.size() / (2 * B) + 1;
    if (mid > answerMax) mid = answerMax;
    set<int> inMachine;
    for (int v : ids) {
        move_inside(v);
        if (press_button() > machineBase + mid) {
            // this is the >midth insect of its type, keep it out
            move_outside(v);
        } else {
            inMachine.insert(v);
        }
    }
    // printf("%lu in machine\n", inMachine.size());
    if (inMachine.size() >= mid * B) {
        // check success; do a GALB on the rest now
        vector<int> remaining;
        for (int v : ids) if (inMachine.count(v) == 0) remaining.push_back(v);
        return mid + getAllLowerBound(remaining, B, answerMax - mid, machineBase + mid);
    } else {
        // check fail; do a GALB with a lower ansMax
        // note that it suffices to only use the ones in the machine
        for (int v : inMachine) move_outside(v);
        vector<int> machinev(begin(inMachine), end(inMachine));
        return getAllLowerBound(machinev, B, mid - 1, machineBase);
    }
}

int min_cardinality(int N) {
    vector<int> reps = getRepresentatives(N);
    int B = reps.size(); // B is the number of types
    // printf("! %d unique types\n", B);
    vector<int> insects;
    set<int> inReps(begin(reps), end(reps));
    for (int i = 0; i < N; ++i) {
        if (inReps.count(i) == 0) insects.push_back(i);
    }
    return getAllLowerBound(insects, B, ceil(N, B) - 1, 1) + 1;
}

Compilation message

insects.cpp: In function 'int getAllLowerBound(std::vector<int>, int, int, int)':
insects.cpp:29:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if (answerMax == 0 || ids.size() < B) return 0; // base case
      |                           ~~~~~~~~~~~^~~
insects.cpp:49:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |     if (inMachine.size() >= mid * B) {
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 300 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 6 ms 336 KB Output is correct
13 Correct 3 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 7 ms 304 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 2 ms 304 KB Output is correct
21 Correct 2 ms 300 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 300 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 6 ms 336 KB Output is correct
13 Correct 3 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 7 ms 304 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 2 ms 304 KB Output is correct
21 Correct 2 ms 300 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 29 ms 324 KB Output is correct
24 Correct 7 ms 336 KB Output is correct
25 Correct 25 ms 336 KB Output is correct
26 Correct 24 ms 336 KB Output is correct
27 Correct 22 ms 300 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 30 ms 436 KB Output is correct
30 Correct 26 ms 428 KB Output is correct
31 Correct 28 ms 308 KB Output is correct
32 Correct 23 ms 328 KB Output is correct
33 Correct 22 ms 292 KB Output is correct
34 Correct 22 ms 324 KB Output is correct
35 Correct 20 ms 464 KB Output is correct
36 Correct 27 ms 336 KB Output is correct
37 Correct 23 ms 316 KB Output is correct
38 Correct 25 ms 296 KB Output is correct
39 Correct 22 ms 316 KB Output is correct
40 Correct 16 ms 320 KB Output is correct
41 Correct 8 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 54 ms 472 KB Output is correct
8 Correct 15 ms 300 KB Output is correct
9 Correct 58 ms 396 KB Output is correct
10 Correct 57 ms 532 KB Output is correct
11 Correct 44 ms 328 KB Output is correct
12 Correct 31 ms 292 KB Output is correct
13 Correct 42 ms 456 KB Output is correct
14 Correct 48 ms 396 KB Output is correct
15 Correct 57 ms 328 KB Output is correct
16 Correct 52 ms 332 KB Output is correct
17 Correct 55 ms 288 KB Output is correct
18 Correct 48 ms 328 KB Output is correct
19 Correct 50 ms 296 KB Output is correct
20 Correct 41 ms 292 KB Output is correct
21 Correct 57 ms 288 KB Output is correct
22 Correct 50 ms 416 KB Output is correct
23 Correct 50 ms 328 KB Output is correct
24 Correct 32 ms 292 KB Output is correct
25 Correct 22 ms 368 KB Output is correct
26 Correct 16 ms 328 KB Output is correct
27 Correct 52 ms 408 KB Output is correct
28 Correct 52 ms 276 KB Output is correct
29 Correct 60 ms 296 KB Output is correct
30 Correct 52 ms 280 KB Output is correct
31 Correct 48 ms 328 KB Output is correct
32 Correct 51 ms 340 KB Output is correct
33 Partially correct 62 ms 416 KB Output is partially correct
34 Partially correct 54 ms 328 KB Output is partially correct
35 Correct 37 ms 292 KB Output is correct
36 Correct 60 ms 276 KB Output is correct
37 Correct 47 ms 288 KB Output is correct
38 Correct 42 ms 384 KB Output is correct
39 Correct 28 ms 288 KB Output is correct
40 Correct 55 ms 328 KB Output is correct
41 Correct 44 ms 276 KB Output is correct
42 Correct 50 ms 380 KB Output is correct
43 Correct 12 ms 300 KB Output is correct
44 Correct 18 ms 304 KB Output is correct
45 Correct 52 ms 276 KB Output is correct
46 Correct 24 ms 296 KB Output is correct
47 Correct 31 ms 296 KB Output is correct
48 Correct 29 ms 348 KB Output is correct