Submission #971082

# Submission time Handle Problem Language Result Execution time Memory
971082 2024-04-27T22:47:16 Z ALeonidou Rarest Insects (IOI22_insects) C++17
10 / 100
22 ms 1100 KB
#include "insects.h"

#include <variant>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

#define ll int
#define F first
#define S second
#define pb push_back
#define sz(x) (ll)x.size()
#define endl "\n"

typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
    
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
    
void printVct(vi &v){
    for (ll i =0; i<sz(v); i++){
            cout<<v[i]<<" ";
    }
    cout<<endl;
}

#define MID ((l+r)/2)

void solve(vi &u, ll l, ll r, vi test_subjects, vi &id){
    if (l == r){
        for (ll i =0; i<sz(test_subjects); i++){
            id[test_subjects[i]] = u[l];
        }
    }
    else{
        vi remaining_test_subjects;

        //go left:
        remaining_test_subjects.clear();
        for (ll i =MID+1; i<r; i++){
            move_outside(u[i]);
        }
        for (ll i = 0; i<sz(test_subjects); i++){
            move_inside(test_subjects[i]);
            ll x = press_button();
            if (x == 2){
                remaining_test_subjects.pb(test_subjects[i]);
            }
            move_outside(test_subjects[i]);
        }
        solve(u, l, MID, remaining_test_subjects, id);
        for (ll i =MID+1; i<r; i++){
            move_inside(u[i]);
        }

        //go right:
        remaining_test_subjects.clear();
        for (ll i =0; i<=MID; i++){
            move_outside(u[i]);
        }
        for (ll i = 0; i<sz(test_subjects); i++){
            move_inside(test_subjects[i]);
            ll x = press_button();
            if (x == 2){
                remaining_test_subjects.pb(test_subjects[i]);
            }
            move_outside(test_subjects[i]);
        }
        solve(u, MID+1, r, remaining_test_subjects, id);
        for (ll i =0; i<=MID; i++){
            move_inside(u[i]);
        }
    }
}

int min_cardinality(int N){
    ll n = N;
    vi v(n);

    //step 1: make list of unique elements
    vi u(1,0);
    move_inside(0);
    for (ll i =1; i<n;i++){
        move_inside(i);
        ll x = press_button();
        if (x == 2){
            move_outside(i);
        }
        else{
            u.pb(i);
        }
    }
    // printVct(u);

    //step 2: binary search
    set <ll> st;
    for (ll i =0; i<sz(u); i++){
        st.insert(u[i]);
    }
    vi test_subjects, id(n);
    for (ll i =0; i<n; i++){
        if (st.find(i) == st.end()){
            test_subjects.pb(i);
            id[i] = -1;
        }
        else{
            id[i] = i;
        }
    }
    solve(u, 0, sz(u)-1, test_subjects, id);

    // printVct(id);

    sort(id.begin(), id.end());

    vi f(n,0);
    for (ll i =0; i<n; i++){
        f[id[i]]++;
    }
    ll ans = 1000000000;
    for (ll i =0; i<n; i++){
        if (f[i]){
            ans = min(ans, f[i]);
        }
    }
    return ans;
}


/*

6
5 8 9 5 9 9

5
1 2 2 3 4


10
1 2 2 6 1 3 3 2 6 1

6
1 2 3 4 5 6

1
1

*/












# Verdict Execution time Memory Grader output
1 Correct 1 ms 540 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 9 ms 440 KB Output is correct
9 Correct 10 ms 692 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 9 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 10 ms 856 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 10 ms 600 KB Output is correct
16 Correct 10 ms 600 KB Output is correct
17 Correct 9 ms 592 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 10 ms 848 KB Output is correct
20 Correct 9 ms 600 KB Output is correct
21 Correct 10 ms 856 KB Output is correct
22 Correct 9 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 540 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 9 ms 440 KB Output is correct
9 Correct 10 ms 692 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 9 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 10 ms 856 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 10 ms 600 KB Output is correct
16 Correct 10 ms 600 KB Output is correct
17 Correct 9 ms 592 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 10 ms 848 KB Output is correct
20 Correct 9 ms 600 KB Output is correct
21 Correct 10 ms 856 KB Output is correct
22 Correct 9 ms 600 KB Output is correct
23 Correct 4 ms 600 KB Output is correct
24 Incorrect 15 ms 1100 KB Too many queries.
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 10 ms 596 KB Output is correct
8 Incorrect 22 ms 700 KB Too many queries.
9 Halted 0 ms 0 KB -