Submission #838474

# Submission time Handle Problem Language Result Execution time Memory
838474 2023-08-27T07:25:01 Z Theo830 Rarest Insects (IOI22_insects) C++17
99.89 / 100
56 ms 684 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int min_cardinality(int N){
    ll n = N;
    set<ll>ex;
    set<ll>olo;
    bool v[n] = {0};
    f(i,0,n){
        move_inside(i);
        olo.insert(i);
        ex.insert(i);
        v[i] = 1;
        if(1 != press_button()){
            ex.erase(i);
            v[i] = 0;
            move_outside(i);
        }
    }
    ll d = ex.size();
    ll l = 2,r = n / d;
    ll ans = 1;
    set<ll>cur = ex;
    while(l <= r){
        ll posa = cur.size();
        for(auto x:olo){
            if(!v[x]){
                posa++;
            }
        }
        r = min(r,posa / d);
        ll mid = (l+r)/2;
        for(auto x:olo){
            if(!v[x]){
                move_inside(x);
                v[x] = 1;
                cur.insert(x);
                if(press_button() > mid){
                    move_outside(x);
                    cur.erase(x);
                    v[x] = 0;
                }
            }
        }
        if((ll)cur.size() == d * mid){
            l = mid + 1;
            ex = cur;
            ans = max(ans,mid);
        }
        else{
            olo = cur;
            for(auto x:cur){
                if(!ex.count(x)){
                    v[x] = 0;
                    move_outside(x);
                }
            }
            cur = ex;
            r = mid - 1;
        }
    }
    return ans;
}
# Verdict Execution time Memory 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 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory 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 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 24 ms 456 KB Output is correct
24 Correct 6 ms 336 KB Output is correct
25 Correct 19 ms 348 KB Output is correct
26 Correct 19 ms 336 KB Output is correct
27 Correct 17 ms 320 KB Output is correct
28 Correct 8 ms 460 KB Output is correct
29 Correct 23 ms 344 KB Output is correct
30 Correct 18 ms 332 KB Output is correct
31 Correct 26 ms 316 KB Output is correct
32 Correct 27 ms 404 KB Output is correct
33 Correct 30 ms 380 KB Output is correct
34 Correct 27 ms 336 KB Output is correct
35 Correct 20 ms 364 KB Output is correct
36 Correct 24 ms 464 KB Output is correct
37 Correct 12 ms 460 KB Output is correct
38 Correct 21 ms 364 KB Output is correct
39 Correct 18 ms 460 KB Output is correct
40 Correct 14 ms 332 KB Output is correct
41 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 37 ms 532 KB Output is correct
8 Correct 12 ms 464 KB Output is correct
9 Correct 52 ms 520 KB Output is correct
10 Correct 39 ms 460 KB Output is correct
11 Correct 22 ms 336 KB Output is correct
12 Correct 28 ms 456 KB Output is correct
13 Correct 52 ms 336 KB Output is correct
14 Correct 29 ms 336 KB Output is correct
15 Correct 49 ms 552 KB Output is correct
16 Correct 54 ms 684 KB Output is correct
17 Correct 47 ms 488 KB Output is correct
18 Correct 56 ms 456 KB Output is correct
19 Partially correct 33 ms 432 KB Output is partially correct
20 Correct 47 ms 508 KB Output is correct
21 Correct 53 ms 488 KB Output is correct
22 Correct 23 ms 336 KB Output is correct
23 Correct 43 ms 336 KB Output is correct
24 Correct 34 ms 440 KB Output is correct
25 Correct 20 ms 428 KB Output is correct
26 Correct 19 ms 432 KB Output is correct
27 Correct 52 ms 452 KB Output is correct
28 Correct 43 ms 492 KB Output is correct
29 Partially correct 39 ms 520 KB Output is partially correct
30 Partially correct 53 ms 516 KB Output is partially correct
31 Correct 52 ms 396 KB Output is correct
32 Correct 44 ms 456 KB Output is correct
33 Correct 42 ms 336 KB Output is correct
34 Correct 42 ms 336 KB Output is correct
35 Partially correct 41 ms 532 KB Output is partially correct
36 Partially correct 46 ms 544 KB Output is partially correct
37 Correct 26 ms 400 KB Output is correct
38 Correct 52 ms 452 KB Output is correct
39 Correct 45 ms 424 KB Output is correct
40 Correct 48 ms 448 KB Output is correct
41 Partially correct 37 ms 456 KB Output is partially correct
42 Partially correct 39 ms 524 KB Output is partially correct
43 Correct 12 ms 208 KB Output is correct
44 Correct 35 ms 336 KB Output is correct
45 Correct 49 ms 532 KB Output is correct
46 Correct 28 ms 452 KB Output is correct
47 Correct 29 ms 380 KB Output is correct
48 Correct 25 ms 436 KB Output is correct