Submission #831667

# Submission time Handle Problem Language Result Execution time Memory
831667 2023-08-20T12:04:51 Z Kaitokid Rarest Insects (IOI22_insects) C++17
99.83 / 100
46 ms 412 KB
#include "insects.h"
    #include<bits/stdc++.h>
    using namespace std;
    /*vector<int>A;
    int fr[20009];
    int cnt[3];
    void move_inside(int x)
    {
        cnt[0]++;
        cout<<"in "<<x<<endl;
        fr[A[x]]++;
    }
    void move_outside(int x)
    {
        cnt[1]++;
        cout<<"out "<<x<<endl;
        fr[A[x]]--;
    }
    int press_button()
    {
        cnt[2]++;
        cout<<"press"<<endl;
        int res=0;
        for(int i=0;i<2000;i++)res=max(res,fr[i]);
        return res;
    }*/
    int n,dst;
    stack<int>st;
    bool nt[20009];
 
    bool ch(int x)
    {
        while(!st.empty()){move_outside(st.top());st.pop();}
        int sz=0;
        vector<int>g;
        for(int i=0;i<n;i++)
        {
            if(nt[i])continue;
            if(sz==0){st.push(i);move_inside(i);sz++;continue;}
            move_inside(i);
            if(press_button()>x){move_outside(i);g.push_back(i);continue;}
            sz++;
            st.push(i);
            if(sz==x*dst)break;
        }
        if(sz==x*dst)
        {
            while(!st.empty()){nt[st.top()]=true;move_outside(st.top());st.pop();}
            return true;
 
        }
        for(int i=0;i<g.size();i++)nt[g[i]]=true;
        return false;
 
    }
    int rss;
    int min_cardinality(int N)
    {
        rss=0;
        n=N;
        dst=0;
        move_inside(0);
        st.push(0);
        dst++;
        for(int i=1;i<n;i++)
        {
            move_inside(i);
            if(press_button()==1){st.push(i);dst++;}
               else move_outside(i);
        }
        int l=1,r=n/dst;
        while(l<r)
        {
            int mid=(l+r+1)/2;
            if(ch(mid)){l=0;r-=mid;rss+=mid;}
            else r=mid-1;
        }
        return l+rss;
    }
    /*
    int main()
    {
 
       A={5,8,9,5,9,9};
       cout<<min_cardinality(6)<<endl;
       cout<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<endl;
        return 0;
    }
    */

Compilation message

insects.cpp: In function 'bool ch(int)':
insects.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i=0;i<g.size();i++)nt[g[i]]=true;
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 304 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 304 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 19 ms 308 KB Output is correct
24 Correct 6 ms 208 KB Output is correct
25 Correct 14 ms 304 KB Output is correct
26 Correct 16 ms 280 KB Output is correct
27 Correct 17 ms 208 KB Output is correct
28 Correct 9 ms 304 KB Output is correct
29 Correct 14 ms 412 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 12 ms 208 KB Output is correct
32 Correct 16 ms 208 KB Output is correct
33 Correct 21 ms 284 KB Output is correct
34 Correct 20 ms 208 KB Output is correct
35 Correct 9 ms 328 KB Output is correct
36 Correct 18 ms 304 KB Output is correct
37 Correct 17 ms 212 KB Output is correct
38 Correct 17 ms 208 KB Output is correct
39 Correct 18 ms 300 KB Output is correct
40 Correct 13 ms 208 KB Output is correct
41 Correct 8 ms 312 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 0 ms 208 KB Output is correct
7 Correct 27 ms 280 KB Output is correct
8 Correct 14 ms 308 KB Output is correct
9 Correct 32 ms 208 KB Output is correct
10 Correct 35 ms 284 KB Output is correct
11 Correct 35 ms 288 KB Output is correct
12 Correct 29 ms 292 KB Output is correct
13 Correct 33 ms 296 KB Output is correct
14 Correct 44 ms 284 KB Output is correct
15 Correct 31 ms 208 KB Output is correct
16 Correct 26 ms 284 KB Output is correct
17 Correct 31 ms 284 KB Output is correct
18 Correct 29 ms 208 KB Output is correct
19 Correct 36 ms 284 KB Output is correct
20 Correct 35 ms 288 KB Output is correct
21 Correct 20 ms 292 KB Output is correct
22 Partially correct 42 ms 304 KB Output is partially correct
23 Correct 40 ms 284 KB Output is correct
24 Correct 40 ms 304 KB Output is correct
25 Correct 20 ms 296 KB Output is correct
26 Correct 16 ms 304 KB Output is correct
27 Correct 33 ms 280 KB Output is correct
28 Correct 26 ms 208 KB Output is correct
29 Partially correct 41 ms 208 KB Output is partially correct
30 Partially correct 45 ms 296 KB Output is partially correct
31 Correct 33 ms 208 KB Output is correct
32 Correct 36 ms 296 KB Output is correct
33 Correct 29 ms 284 KB Output is correct
34 Correct 34 ms 292 KB Output is correct
35 Partially correct 36 ms 288 KB Output is partially correct
36 Correct 29 ms 208 KB Output is correct
37 Correct 46 ms 208 KB Output is correct
38 Correct 42 ms 288 KB Output is correct
39 Correct 30 ms 296 KB Output is correct
40 Correct 28 ms 292 KB Output is correct
41 Correct 30 ms 284 KB Output is correct
42 Partially correct 37 ms 284 KB Output is partially correct
43 Correct 9 ms 208 KB Output is correct
44 Correct 29 ms 280 KB Output is correct
45 Correct 22 ms 280 KB Output is correct
46 Correct 27 ms 308 KB Output is correct
47 Correct 22 ms 296 KB Output is correct
48 Correct 36 ms 292 KB Output is correct