Submission #783354

# Submission time Handle Problem Language Result Execution time Memory
783354 2023-07-14T21:26:41 Z FEDIKUS Rarest Insects (IOI22_insects) C++17
100 / 100
49 ms 336 KB
#include "insects.h"
#include<bits/stdc++.h>

using namespace std;

const int maxn=2010;

int n;
int tren[maxn];
int perm[maxn];
int klk[maxn];
int unutra=0;
int korak=1;
int raz;
bool nemoj[maxn];
bool stabrekojikurac[maxn];

void ubaci(int i){
  if(tren[i]!=0) return;
  tren[i]=korak;
  move_inside(perm[i]);
  unutra++;
}
void izbaci(int i){
  if(tren[i]==0) return;
  tren[i]=0;
  move_outside(perm[i]);
  unutra--;
}
int pitaj(){
  return press_button();
}
int nadji(){
  for(int i=0;i<n;i++){
    ubaci(i);
    if(pitaj()>1){
      izbaci(i);
    }
  }
  return unutra;
}

mt19937 rng(23479);

bool probaj(int gran,int sled){ // da li je >=
  korak++;
  for(int i=0;i<n;i++){
    if(unutra==raz*gran) {
      for(int i=0;i<n;i++) stabrekojikurac[i]=false;
      return true;
    }
    if(tren[i]!=0) continue;
    if(nemoj[i]) continue;
    ubaci(i);
    if((klk[i]=pitaj())>gran){
      izbaci(i);
      stabrekojikurac[i]=true;
    }
  }
  if(unutra==raz*gran) {
    for(int i=0;i<n;i++) stabrekojikurac[i]=false;
    return true;
  }
  for(int i=0;i<n;i++) if(stabrekojikurac[i]) {nemoj[i]=true; stabrekojikurac[i]=false;}
  for(int i=0;i<n;i++) if(tren[i]==korak && klk[i]>sled) izbaci(i);
  korak--;
  return false;
}

int min_cardinality(int _n){
  n=_n;
  for(int i=0;i<n;i++) perm[i]=i;
  shuffle(perm,perm+n,rng);
  raz=nadji();
  int l=1,r=n/raz;
  int res=-1;
  while(l<=r){
    int mid=l+(r-l)/2;
    int sled=l+(mid-1-l)/2;
    if(probaj(mid,sled)){
      res=mid;
      l=mid+1;
    }else r=mid-1;
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 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 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 4 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 5 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 3 ms 260 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 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 1 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 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 4 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 5 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 3 ms 260 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 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 18 ms 316 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 17 ms 208 KB Output is correct
26 Correct 23 ms 324 KB Output is correct
27 Correct 15 ms 320 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 17 ms 320 KB Output is correct
30 Correct 17 ms 324 KB Output is correct
31 Correct 20 ms 316 KB Output is correct
32 Correct 25 ms 320 KB Output is correct
33 Correct 16 ms 336 KB Output is correct
34 Correct 18 ms 208 KB Output is correct
35 Correct 18 ms 320 KB Output is correct
36 Correct 23 ms 208 KB Output is correct
37 Correct 14 ms 208 KB Output is correct
38 Correct 26 ms 304 KB Output is correct
39 Correct 17 ms 328 KB Output is correct
40 Correct 10 ms 324 KB Output is correct
41 Correct 7 ms 328 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 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 35 ms 320 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 41 ms 324 KB Output is correct
10 Correct 43 ms 324 KB Output is correct
11 Correct 36 ms 324 KB Output is correct
12 Correct 22 ms 208 KB Output is correct
13 Correct 38 ms 320 KB Output is correct
14 Correct 39 ms 324 KB Output is correct
15 Correct 32 ms 320 KB Output is correct
16 Correct 38 ms 208 KB Output is correct
17 Correct 41 ms 208 KB Output is correct
18 Correct 38 ms 324 KB Output is correct
19 Correct 41 ms 308 KB Output is correct
20 Correct 41 ms 308 KB Output is correct
21 Correct 41 ms 208 KB Output is correct
22 Correct 24 ms 320 KB Output is correct
23 Correct 17 ms 312 KB Output is correct
24 Correct 28 ms 208 KB Output is correct
25 Correct 19 ms 208 KB Output is correct
26 Correct 15 ms 208 KB Output is correct
27 Correct 37 ms 208 KB Output is correct
28 Correct 33 ms 308 KB Output is correct
29 Correct 39 ms 208 KB Output is correct
30 Correct 30 ms 308 KB Output is correct
31 Correct 21 ms 320 KB Output is correct
32 Correct 37 ms 308 KB Output is correct
33 Correct 39 ms 304 KB Output is correct
34 Correct 32 ms 208 KB Output is correct
35 Correct 49 ms 328 KB Output is correct
36 Correct 41 ms 328 KB Output is correct
37 Correct 43 ms 320 KB Output is correct
38 Correct 38 ms 328 KB Output is correct
39 Correct 41 ms 328 KB Output is correct
40 Correct 40 ms 324 KB Output is correct
41 Correct 42 ms 320 KB Output is correct
42 Correct 42 ms 208 KB Output is correct
43 Correct 9 ms 328 KB Output is correct
44 Correct 25 ms 308 KB Output is correct
45 Correct 36 ms 320 KB Output is correct
46 Correct 20 ms 208 KB Output is correct
47 Correct 17 ms 208 KB Output is correct
48 Correct 18 ms 324 KB Output is correct