Submission #1173749

#TimeUsernameProblemLanguageResultExecution timeMemory
1173749SpyrosAlivRarest Insects (IOI22_insects)C++20
25 / 100
97 ms424 KiB
#include <bits/stdc++.h>
using namespace std;

void move_inside(int x);
void move_outside(int x);
int press_button();

int min_cardinality(int n) {
    vector<int> lvl;
    int comps = 0;
    vector<bool> added(n, false);
    for (int i = 0; i < n; i++) {
        move_inside(i);
        int x = press_button();
        if (x == 1) {
            comps++;
            added[i] = true;
        }
        else {
            move_outside(i);
            lvl.push_back(i);
        }
    }
    if (comps <= sqrt(n)) {
        vector<bool> found(n, false);
        for (int i = 0; i < n; i++) {
            if (added[i]) {
                move_outside(i);
            }
        }
        int mn = n;
        for (int i = 0; i < n; i++) {
            if (added[i]) {
                int s = 1;
                move_inside(i);
                for (int j = 0; j < n; j++) {
                    if (added[j] || found[j]) continue;
                    move_inside(j);
                    int x = press_button();
                    if (x == 2) {
                        s++;
                        found[j] = true;
                    }
                    move_outside(j);
                }
                mn = min(mn, s); 
                move_outside(i);
            }
        }
        return mn;
    }
    else {
        int fin = 1;
        for (int curr = 2; curr <= n / comps; curr++) {
            int tot = 0;
            for (int i = 0; i < n; i++) {
                if (added[i]) continue;
                move_inside(i);
                int x = press_button();
                if (x == curr) {
                    added[i] = true;
                    tot++;
                }
                else {
                    move_outside(i);
                }
            }
            if (tot != comps) {
                break;
            }
            fin = curr;
        }
        return fin;
    }
    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...