Submission #1214204

#TimeUsernameProblemLanguageResultExecution timeMemory
1214204thangdz2k7Rarest Insects (IOI22_insects)C++20
Compilation error
0 ms0 KiB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

int min_cardinality(int N){
    vector <int> used(N, 0);
    int num = 0;

    auto add = [&](int i) -> void {
        if (used[i]) continue;
        move_inside(i);
        num ++;
        used[i] = 1;
    };

    auto del = [&](int i) -> void {
        if (!used[i]) continue;
        move_outside(i);
        num --;
        used[i] = 0;
    };

    auto qry = [&]() -> int {
        if (num == 1) return 1;
        return press_button();
    };

    for (int i = 0; i < N; ++ i){
        add(i);
        if (qry() > 1) del(i);
    }

    if (num == 1) return N;
    if (num == N) return 1;

    int D = num;
    vector <int> valid = used;

    auto check = [&](int mid){
        for (int i = 0; i < N; ++ i){
            if (!used[i]){
                add(i);
                if (qry() > mid) del(i);
            }
        }

        if (num == D * mid){
            valid = used;
            return true;
        }

        for (int i = 0; i < N; ++ i) if (!valid[i]) del(i);

        return false;
    }

    int low = 1, high = N / D;
    while (low < high){
        int mid = (low + high + 1) >> 1;
        if (check(mid)) low = mid;
        else high = mid - 1;
    }

    return low;
}

Compilation message (stderr)

insects.cpp: In lambda function:
insects.cpp:11:22: error: continue statement not within a loop
   11 |         if (used[i]) continue;
      |                      ^~~~~~~~
insects.cpp: In lambda function:
insects.cpp:18:23: error: continue statement not within a loop
   18 |         if (!used[i]) continue;
      |                       ^~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:58:5: error: expected ',' or ';' before 'int'
   58 |     int low = 1, high = N / D;
      |     ^~~
insects.cpp:59:18: error: 'high' was not declared in this scope
   59 |     while (low < high){
      |                  ^~~~
insects.cpp:59:12: error: 'low' was not declared in this scope; did you mean 'pow'?
   59 |     while (low < high){
      |            ^~~
      |            pow
insects.cpp:65:12: error: 'low' was not declared in this scope; did you mean 'pow'?
   65 |     return low;
      |            ^~~
      |            pow