Submission #926861

# Submission time Handle Problem Language Result Execution time Memory
926861 2024-02-14T01:06:26 Z beaboss Rarest Insects (IOI22_insects) C++17
49.85 / 100
116 ms 1520 KB
// Source: https://oj.uz/problem/view/IOI22_insects
// 
#include "insects.h"
#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;

typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef vector<int> vi;

#define FOR(i, a, b) for (int i = (a); i<b; i++)

bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }

bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }

set<int> in, out;

void gout(int i) {
  in.erase(i);
  out.insert(i);
  move_outside(i);
}

void gin(int i) {
  out.erase(i);
  in.insert(i);
  move_inside(i);
}

int min_cardinality(int n) {

  // cout << n << endl;
  FOR(i, 0, n) out.insert(i);

  int d = n;
  FOR(i, 0, n) {
    gin(i);
    if (press_button() > 1) {
      gout(i);
      d--;
    }
  }
  // cout << 'd' << endl;

  // d = press_button(); // distinct numbers
  // cout << d << endl;
  set<int> oth = in;
  for (auto val: oth) {
    // cout << val << endl;
    gout(val);
    // cout << val << endl;
  }

  int alr = 0;
  // cout << 'd' << endl;
  int prv = -1;
  int lo  = 1;
  int hi = n;
  while (lo < hi) {
    int t = (lo + hi + 1) / (2);
    prv = out.size();
    // cout << out.size() << t << endl;
    // for (auto val: out) {
    //   cout << val << ' ';
    // }
    // cout << endl;
    // testing t
    set<int> oth = out;
    for (auto val: oth) {
      gin(val);
      if (press_button() > t) {
        gout(val);
      }
    }
    // cout << press_button() << endl;
    if (in.size() == t * d) { // all here --- erase this section
      // alr += t;
      // for (auto it = in.begin(); it != in.end();) {
      //   move_outside(*it);
      //   it++;
      //   in.erase(prev(it, 1));
      // }
      // set<int> oth = in;
      // for (auto val: oth) gout(val);
      lo = t;
    } else { // erase everything not in this section
      for (auto it = out.begin(); it != out.end();) {
        it++;
        out.erase(prev(it, 1));
      }
      set<int> oth = in;
      for (auto val: oth) gout(val);
      hi = t-1;
    }

  }
  // cout << alr << endl;

  return lo;

}













Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:85:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |     if (in.size() == t * d) { // all here --- erase this section
      |         ~~~~~~~~~~^~~~~~~~
insects.cpp:63:7: warning: unused variable 'alr' [-Wunused-variable]
   63 |   int alr = 0;
      |       ^~~
insects.cpp:65:7: warning: variable 'prv' set but not used [-Wunused-but-set-variable]
   65 |   int prv = -1;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 8 ms 600 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 5 ms 700 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 5 ms 600 KB Output is correct
15 Correct 5 ms 600 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 8 ms 600 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 8 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 8 ms 600 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 5 ms 700 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 5 ms 600 KB Output is correct
15 Correct 5 ms 600 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 8 ms 600 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 8 ms 600 KB Output is correct
23 Correct 14 ms 484 KB Output is correct
24 Correct 48 ms 1308 KB Output is correct
25 Correct 49 ms 804 KB Output is correct
26 Correct 42 ms 1096 KB Output is correct
27 Correct 14 ms 600 KB Output is correct
28 Correct 36 ms 964 KB Output is correct
29 Correct 31 ms 684 KB Output is correct
30 Correct 41 ms 984 KB Output is correct
31 Correct 31 ms 968 KB Output is correct
32 Correct 38 ms 1020 KB Output is correct
33 Correct 39 ms 936 KB Output is correct
34 Correct 45 ms 776 KB Output is correct
35 Correct 34 ms 804 KB Output is correct
36 Correct 40 ms 1092 KB Output is correct
37 Correct 48 ms 936 KB Output is correct
38 Correct 47 ms 1060 KB Output is correct
39 Correct 52 ms 808 KB Output is correct
40 Correct 50 ms 1092 KB Output is correct
41 Correct 50 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Partially correct 0 ms 344 KB Output is partially correct
7 Correct 27 ms 532 KB Output is correct
8 Partially correct 110 ms 1028 KB Output is partially correct
9 Partially correct 85 ms 1096 KB Output is partially correct
10 Partially correct 86 ms 1000 KB Output is partially correct
11 Partially correct 30 ms 592 KB Output is partially correct
12 Partially correct 74 ms 1484 KB Output is partially correct
13 Partially correct 48 ms 732 KB Output is partially correct
14 Partially correct 82 ms 940 KB Output is partially correct
15 Partially correct 94 ms 1180 KB Output is partially correct
16 Partially correct 64 ms 780 KB Output is partially correct
17 Partially correct 75 ms 1176 KB Output is partially correct
18 Partially correct 97 ms 1164 KB Output is partially correct
19 Partially correct 87 ms 936 KB Output is partially correct
20 Partially correct 79 ms 940 KB Output is partially correct
21 Partially correct 99 ms 852 KB Output is partially correct
22 Partially correct 92 ms 940 KB Output is partially correct
23 Partially correct 113 ms 1188 KB Output is partially correct
24 Partially correct 111 ms 1176 KB Output is partially correct
25 Partially correct 114 ms 828 KB Output is partially correct
26 Partially correct 116 ms 996 KB Output is partially correct
27 Partially correct 114 ms 1176 KB Output is partially correct
28 Partially correct 108 ms 844 KB Output is partially correct
29 Partially correct 96 ms 932 KB Output is partially correct
30 Partially correct 114 ms 1252 KB Output is partially correct
31 Partially correct 105 ms 932 KB Output is partially correct
32 Partially correct 92 ms 1156 KB Output is partially correct
33 Partially correct 89 ms 1084 KB Output is partially correct
34 Partially correct 94 ms 1240 KB Output is partially correct
35 Partially correct 102 ms 1152 KB Output is partially correct
36 Partially correct 96 ms 928 KB Output is partially correct
37 Partially correct 101 ms 944 KB Output is partially correct
38 Partially correct 107 ms 1088 KB Output is partially correct
39 Partially correct 111 ms 1436 KB Output is partially correct
40 Partially correct 111 ms 952 KB Output is partially correct
41 Partially correct 105 ms 1412 KB Output is partially correct
42 Partially correct 107 ms 936 KB Output is partially correct
43 Partially correct 11 ms 856 KB Output is partially correct
44 Partially correct 32 ms 764 KB Output is partially correct
45 Partially correct 44 ms 604 KB Output is partially correct
46 Partially correct 88 ms 1248 KB Output is partially correct
47 Partially correct 71 ms 1232 KB Output is partially correct
48 Partially correct 85 ms 1236 KB Output is partially correct