Submission #755140

# Submission time Handle Problem Language Result Execution time Memory
755140 2023-06-09T12:41:05 Z Rafi22 Rarest Insects (IOI22_insects) C++17
99.89 / 100
68 ms 428 KB
#include <bits/stdc++.h>
#include "insects.h"

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

int ans=1,m;
/*
int a[107];
map<int,int>ile;

set<int>W;

void move_inside(int i)
{
   W.insert(i);
}
void move_outside(int i)
{
   W.erase(i);
}
int press_button()
{
    ile.clear();
    int ans=0;
    for(auto x:W) ans=max(ans,++ile[a[x]]);
    return ans;
}
*/
void rek(vector<int>a)
{
    if(sz(a)<m) return ;
    int k=(sz(a)/m+1)/2;
    vector<int>T,N;
    bool is=0;
    for(auto x:a)
    {
        move_inside(x);
        if(press_button()>ans+k)
        {
            move_outside(x);
            N.pb(x);
        }
        else T.pb(x);
    }
    if(sz(T)==m*k)
    {
        ans+=k;
        rek(N);
    }
    else
    {
        for(auto x:T) move_outside(x);
        rek(T);
    }
}

int min_cardinality(int n)
{
    vector<int>V,X;
    for(int i=0;i<n;i++)
    {
        move_inside(i);
        if(press_button()>1)
        {
            move_outside(i);
            V.pb(i);
        }
        else
        {
            X.pb(i);
            m++;
        }
    }
    rek(V);
    return ans;
}
/*
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<min_cardinality(n)<<endl;
    return 0;
}
/*
6
5 8 9 5 9 9

*/

Compilation message

insects.cpp:97:1: warning: "/*" within comment [-Wcomment]
   97 | /*
      |  
insects.cpp: In function 'void rek(std::vector<int>)':
insects.cpp:45:10: warning: unused variable 'is' [-Wunused-variable]
   45 |     bool is=0;
      |          ^~
# 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 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 6 ms 208 KB Output is correct
10 Correct 5 ms 300 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 7 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 5 ms 296 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 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 4 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 6 ms 208 KB Output is correct
10 Correct 5 ms 300 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 7 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 5 ms 296 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 30 ms 296 KB Output is correct
24 Correct 9 ms 296 KB Output is correct
25 Correct 25 ms 308 KB Output is correct
26 Correct 22 ms 208 KB Output is correct
27 Correct 15 ms 304 KB Output is correct
28 Correct 8 ms 300 KB Output is correct
29 Correct 24 ms 308 KB Output is correct
30 Correct 23 ms 208 KB Output is correct
31 Correct 28 ms 300 KB Output is correct
32 Correct 25 ms 328 KB Output is correct
33 Correct 24 ms 208 KB Output is correct
34 Correct 24 ms 296 KB Output is correct
35 Correct 29 ms 312 KB Output is correct
36 Correct 31 ms 304 KB Output is correct
37 Correct 27 ms 208 KB Output is correct
38 Correct 17 ms 292 KB Output is correct
39 Correct 20 ms 208 KB Output is correct
40 Correct 18 ms 208 KB Output is correct
41 Correct 10 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 220 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 60 ms 316 KB Output is correct
8 Correct 21 ms 208 KB Output is correct
9 Correct 54 ms 324 KB Output is correct
10 Correct 67 ms 296 KB Output is correct
11 Correct 54 ms 300 KB Output is correct
12 Correct 23 ms 304 KB Output is correct
13 Correct 52 ms 308 KB Output is correct
14 Correct 62 ms 296 KB Output is correct
15 Correct 64 ms 304 KB Output is correct
16 Correct 55 ms 304 KB Output is correct
17 Correct 53 ms 316 KB Output is correct
18 Correct 50 ms 312 KB Output is correct
19 Partially correct 68 ms 300 KB Output is partially correct
20 Correct 57 ms 300 KB Output is correct
21 Correct 60 ms 428 KB Output is correct
22 Correct 56 ms 296 KB Output is correct
23 Correct 45 ms 428 KB Output is correct
24 Correct 36 ms 416 KB Output is correct
25 Correct 15 ms 304 KB Output is correct
26 Correct 23 ms 292 KB Output is correct
27 Correct 57 ms 296 KB Output is correct
28 Correct 58 ms 412 KB Output is correct
29 Partially correct 63 ms 308 KB Output is partially correct
30 Partially correct 47 ms 296 KB Output is partially correct
31 Correct 52 ms 312 KB Output is correct
32 Correct 65 ms 292 KB Output is correct
33 Correct 28 ms 328 KB Output is correct
34 Correct 46 ms 300 KB Output is correct
35 Partially correct 50 ms 308 KB Output is partially correct
36 Partially correct 64 ms 300 KB Output is partially correct
37 Correct 48 ms 300 KB Output is correct
38 Correct 35 ms 292 KB Output is correct
39 Correct 49 ms 288 KB Output is correct
40 Correct 60 ms 296 KB Output is correct
41 Partially correct 55 ms 304 KB Output is partially correct
42 Partially correct 65 ms 296 KB Output is partially correct
43 Correct 9 ms 208 KB Output is correct
44 Correct 48 ms 304 KB Output is correct
45 Correct 49 ms 424 KB Output is correct
46 Correct 22 ms 300 KB Output is correct
47 Correct 29 ms 300 KB Output is correct
48 Correct 32 ms 208 KB Output is correct