Submission #812828

# Submission time Handle Problem Language Result Execution time Memory
812828 2023-08-07T11:16:19 Z blackyuki Rarest Insects (IOI22_insects) C++17
100 / 100
44 ms 272 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001001001;
#include "insects.h"

int min_cardinality(int N) {
  vb dead(N,false),flag(N,false);
  ll cnt=0;
  auto add=[&](ll i){
    move_inside(i);
    cnt++;
    flag[i]=true;
    return press_button();
  };
  auto del=[&](ll i){
    move_outside(i);
    cnt--;
    flag[i]=false;
  };
  rep(i,N){
    if(add(i)>1)del(i);
  }
  ll s=cnt,f=1;
  ll n=N-cnt;
  dead=flag;
  while(n>=s){
    ll md=(n+s*2-1)/(s*2);
    rep(i,N)if(!dead[i]&&flag[i]&&cnt>s*f+md)del(i);
    rep(i,N)if(!dead[i]&&!flag[i]){
      if(add(i)>f+md)del(i);
    }
    if(cnt==(f+md)*s){
      f+=md;
      rep(i,N)if(!dead[i]&&flag[i]){
        n--;dead[i]=true;
      }
    }
    else{
      rep(i,N)if(!dead[i]&&!flag[i]){
        n--;dead[i]=true;
      }
    }
  }
  return f;
}
# 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 1 ms 208 KB Output is correct
6 Correct 5 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 5 ms 208 KB Output is correct
10 Correct 2 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 2 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 2 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 252 KB Output is correct
19 Correct 3 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 2 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 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 5 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 5 ms 208 KB Output is correct
10 Correct 2 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 2 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 2 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 252 KB Output is correct
19 Correct 3 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 22 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 24 ms 208 KB Output is correct
26 Correct 20 ms 208 KB Output is correct
27 Correct 17 ms 208 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 16 ms 208 KB Output is correct
30 Correct 16 ms 208 KB Output is correct
31 Correct 17 ms 208 KB Output is correct
32 Correct 24 ms 208 KB Output is correct
33 Correct 19 ms 272 KB Output is correct
34 Correct 26 ms 208 KB Output is correct
35 Correct 18 ms 208 KB Output is correct
36 Correct 17 ms 208 KB Output is correct
37 Correct 20 ms 208 KB Output is correct
38 Correct 18 ms 208 KB Output is correct
39 Correct 16 ms 208 KB Output is correct
40 Correct 11 ms 208 KB Output is correct
41 Correct 4 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 0 ms 208 KB Output is correct
7 Correct 40 ms 208 KB Output is correct
8 Correct 11 ms 208 KB Output is correct
9 Correct 33 ms 208 KB Output is correct
10 Correct 38 ms 208 KB Output is correct
11 Correct 34 ms 208 KB Output is correct
12 Correct 25 ms 208 KB Output is correct
13 Correct 38 ms 208 KB Output is correct
14 Correct 33 ms 208 KB Output is correct
15 Correct 35 ms 208 KB Output is correct
16 Correct 36 ms 208 KB Output is correct
17 Correct 44 ms 208 KB Output is correct
18 Correct 38 ms 208 KB Output is correct
19 Correct 37 ms 208 KB Output is correct
20 Correct 33 ms 208 KB Output is correct
21 Correct 37 ms 208 KB Output is correct
22 Correct 41 ms 208 KB Output is correct
23 Correct 37 ms 208 KB Output is correct
24 Correct 27 ms 208 KB Output is correct
25 Correct 16 ms 208 KB Output is correct
26 Correct 15 ms 208 KB Output is correct
27 Correct 31 ms 208 KB Output is correct
28 Correct 19 ms 208 KB Output is correct
29 Correct 41 ms 208 KB Output is correct
30 Correct 33 ms 208 KB Output is correct
31 Correct 39 ms 208 KB Output is correct
32 Correct 38 ms 208 KB Output is correct
33 Correct 39 ms 208 KB Output is correct
34 Correct 39 ms 208 KB Output is correct
35 Correct 36 ms 208 KB Output is correct
36 Correct 36 ms 208 KB Output is correct
37 Correct 21 ms 208 KB Output is correct
38 Correct 34 ms 208 KB Output is correct
39 Correct 19 ms 208 KB Output is correct
40 Correct 37 ms 208 KB Output is correct
41 Correct 36 ms 208 KB Output is correct
42 Correct 35 ms 208 KB Output is correct
43 Correct 8 ms 208 KB Output is correct
44 Correct 27 ms 208 KB Output is correct
45 Correct 39 ms 208 KB Output is correct
46 Correct 20 ms 208 KB Output is correct
47 Correct 23 ms 208 KB Output is correct
48 Correct 20 ms 208 KB Output is correct