답안 #783156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783156 2023-07-14T16:17:29 Z mousebeaver 드문 곤충 (IOI22_insects) C++17
88.2 / 100
88 ms 464 KB
#include <bits/stdc++.h>
    #include "insects.h"
    #define pii pair<int, int>
    using namespace std;
     
    set<pii> inside;
    set<pii> outside; //Random key, insect index
    int types = -1;
    int offset = 0;
     
    int countTypes()
    {
        int pb = press_button();
        while(inside.size() && pb > 1)
        {
            for(int i = pb; i > 1; i--)
            {
                move_outside((*inside.begin()).second);
                outside.insert(*inside.begin());
                inside.erase(inside.begin());
            }
            pb = press_button();
        }
     
        vector<pii> a(0);
        for(pii i : outside)
        {
            a.push_back(i);
        }
        for(pii i : a)
        {
            move_inside(i.second);
            inside.insert(i);
            outside.erase(i);
            if(inside.size() > 1 && press_button() > 1)
            {
                move_outside(i.second);
                outside.insert(i);
                inside.erase(i);
            }
        }
     
        return inside.size();
    }
     
    bool test(int k) //Every type at least k insects?
    {
        int pb = press_button();
        while(pb > k)
            {
                for(int i = pb; i > k; i--)
                {
                    move_outside((*inside.begin()).second);
                    outside.insert(*inside.begin());
                    inside.erase(inside.begin());
                }
                pb = press_button();
            }
     
        vector<pii> a(0);
        for(pii i : outside)
        {
            a.push_back(i);
        }
        for(pii i : a)
        {
            move_inside(i.second);
            inside.insert(i);
            outside.erase(i);
            if((int) inside.size() > k)
            {
                if(press_button() > k)
                {
                    move_outside(i.second);
                    outside.insert(i);
                    inside.erase(i);
                }
            }
        }
     
        return((int) inside.size() == k*types);
    }
     
    int min_cardinality(int N)
    {
        srand(43);
        for(int i = 0; i < N; i++)
        {
            outside.insert({rand()%100000, i});
        }
     
        types = countTypes();
        if(types <= 5)
        {
            while(inside.size())
            {
                move_outside((*inside.begin()).second);
                outside.insert(*inside.begin());
                inside.erase(inside.begin());            
            }
            vector<int> a(N);
            int counter = 0;
            for(pii p : outside)
            {
                a[counter] = p.second;
                counter++;
            }
            vector<int> card(N, -1);
            int lastcounter = 0;
            for(int i = 0; i < N; i++)
            {
                if(types > 1 && card[a[i]] == -1)
                {
                    types--;
                    move_inside(a[i]);
                    vector<int> machine = {a[i]};
                    for(int j = i+1; j < N; j++)
                    {
                        if(card[a[j]]  == -1)
                        {
                            move_inside(a[j]);
                            machine.push_back(a[j]);
                            int state = press_button();
                            if(state != (int) machine.size())
                            {
                                move_outside(a[j]);
                                machine.pop_back();
                            }
                        }
                    }
                    for(int j : machine)
                    {
                        card[j] = machine.size();
                        move_outside(j);
                    }
                }
                else if(card[a[i]] == -1)
                {
                    lastcounter++;
                }
            }
            for(int i = 0; i < N; i++)
            {
                card[i] = (card[i] == -1 ? lastcounter : card[i]);
            }
        
            return *min_element(card.begin(), card.end());
        }
        int left = 1;
        int right = N/types;
     
        while(left < right)
        {
            int mid = (left+right+1)/2;
            if(right-left > 10)
            {
                mid = left + (right-left)/4;
            }
            if(test(mid))
            {
                if(right+1-(right-left)/4 < mid)
                {
                    offset += mid;
                    while(inside.size())
                    {
                        move_outside((*inside.begin()).second);
                        inside.erase(inside.begin());
                    }
                    if(countTypes() < types)
                    {
                        return offset;
                    }
                    right = right-mid;
                    left = 1;
                }
                else
                {
                    left = mid;
                }
            }
            else
            {
                right = mid-1;
            }
        }
     
        return left+offset;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 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 7 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 7 ms 208 KB Output is correct
15 Correct 8 ms 308 KB Output is correct
16 Correct 7 ms 208 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 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 7 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 7 ms 208 KB Output is correct
15 Correct 8 ms 308 KB Output is correct
16 Correct 7 ms 208 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 6 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 8 ms 336 KB Output is correct
24 Correct 9 ms 352 KB Output is correct
25 Correct 27 ms 336 KB Output is correct
26 Correct 31 ms 336 KB Output is correct
27 Correct 18 ms 336 KB Output is correct
28 Correct 8 ms 336 KB Output is correct
29 Correct 26 ms 336 KB Output is correct
30 Correct 37 ms 336 KB Output is correct
31 Correct 23 ms 336 KB Output is correct
32 Correct 33 ms 336 KB Output is correct
33 Correct 34 ms 336 KB Output is correct
34 Correct 44 ms 336 KB Output is correct
35 Correct 43 ms 336 KB Output is correct
36 Correct 28 ms 352 KB Output is correct
37 Correct 42 ms 336 KB Output is correct
38 Correct 33 ms 464 KB Output is correct
39 Correct 23 ms 336 KB Output is correct
40 Correct 12 ms 336 KB Output is correct
41 Correct 10 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 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 17 ms 336 KB Output is correct
8 Correct 16 ms 336 KB Output is correct
9 Partially correct 80 ms 336 KB Output is partially correct
10 Partially correct 49 ms 336 KB Output is partially correct
11 Correct 34 ms 336 KB Output is correct
12 Correct 28 ms 336 KB Output is correct
13 Partially correct 45 ms 336 KB Output is partially correct
14 Partially correct 76 ms 336 KB Output is partially correct
15 Partially correct 41 ms 336 KB Output is partially correct
16 Partially correct 74 ms 336 KB Output is partially correct
17 Partially correct 84 ms 336 KB Output is partially correct
18 Partially correct 57 ms 336 KB Output is partially correct
19 Partially correct 84 ms 336 KB Output is partially correct
20 Partially correct 85 ms 336 KB Output is partially correct
21 Partially correct 48 ms 336 KB Output is partially correct
22 Partially correct 82 ms 336 KB Output is partially correct
23 Partially correct 76 ms 336 KB Output is partially correct
24 Partially correct 54 ms 336 KB Output is partially correct
25 Correct 22 ms 336 KB Output is correct
26 Correct 19 ms 336 KB Output is correct
27 Partially correct 83 ms 336 KB Output is partially correct
28 Partially correct 64 ms 388 KB Output is partially correct
29 Partially correct 86 ms 336 KB Output is partially correct
30 Partially correct 59 ms 336 KB Output is partially correct
31 Partially correct 77 ms 336 KB Output is partially correct
32 Partially correct 59 ms 336 KB Output is partially correct
33 Partially correct 72 ms 336 KB Output is partially correct
34 Partially correct 53 ms 336 KB Output is partially correct
35 Partially correct 49 ms 384 KB Output is partially correct
36 Partially correct 88 ms 336 KB Output is partially correct
37 Partially correct 60 ms 336 KB Output is partially correct
38 Partially correct 75 ms 336 KB Output is partially correct
39 Partially correct 61 ms 336 KB Output is partially correct
40 Partially correct 66 ms 336 KB Output is partially correct
41 Partially correct 69 ms 336 KB Output is partially correct
42 Partially correct 81 ms 336 KB Output is partially correct
43 Partially correct 22 ms 336 KB Output is partially correct
44 Partially correct 84 ms 336 KB Output is partially correct
45 Correct 36 ms 404 KB Output is correct
46 Correct 27 ms 336 KB Output is correct
47 Correct 22 ms 336 KB Output is correct
48 Correct 27 ms 336 KB Output is correct