Submission #878579

# Submission time Handle Problem Language Result Execution time Memory
878579 2023-11-24T20:10:41 Z Clan328 Rarest Insects (IOI22_insects) C++17
42.69 / 100
132 ms 1428 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define nL '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const ll MOD = 1e9 + 7;

void settings()__attribute__((constructor));

int ipow(int a, int n) {
   if (n == 0) return 1;
   int x = ipow(a, n/2);
   if (n % 2 == 0) return x*x;
   return x*x*a;
}

template <typename T>
ostream& operator<<(ostream& stream, const vector<T>& v) {
  for (auto elem : v) 
    stream << elem << " ";
  return stream;
}

template <typename T>
istream& operator>>(istream& stream, vector<T>& v){
   for(auto &elem : v)
    stream >> elem;
   return stream;
}

vi first;

bool check(int N, int rarity) {
  vi inside, outside;

  for (int i = 0; i < N; i++) {
    move_inside(i);
    if (i >= rarity && press_button() > rarity) {
      move_outside(i);
      outside.pb(i);
    } else {
      inside.pb(i);
    }
  }

  for (int i = 0; i < inside.size(); i++) move_outside(inside[i]);

  if (inside.size() % rarity != 0) return true;
  if (inside.size()/rarity > outside.size()) return true;

  // if (rarity == 1) {
  //   cout << outside << nL;
  // }

  vi outside2;
  for (int i = 0; i < outside.size(); i++) {
    move_inside(outside[i]);
    if (press_button() == 1) {
      outside2.pb(outside[i]);
    } else {
      move_outside(outside[i]);
    }
  }

  // if (rarity == 6) {
  //   cout << outside2 << nL;
  // }

  bool res = false;
  int curr = press_button();
  for (int i = 0; i < first.size() && !res; i++) {
    move_inside(first[i]);
    if (press_button() == curr) {
      res = true;
    }
    move_outside(first[i]);
  }

  for (int i = 0; i < outside2.size(); i++) move_outside(outside2[i]);

  return res;
}

int min_cardinality(int N) {
  first = vi();
  for (int i = 0; i < N; i++) {
    move_inside(i);
    if (press_button() == 1) {
      first.pb(i);
    } else {
      move_outside(i);
    }
  }
  for (int i = 0; i < first.size(); i++) move_outside(first[i]);

  if (first.size() == 1) return N;
  if (first.size() > N/2) return 1;

  int maxN = (N-first.size())+1;
  int lo = 1, hi = maxN-1, res = maxN, mid;
  while (lo <= hi) {
    mid = (lo+hi)/2;
    if (check(N, mid)) {
      res = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }

  return res;
}

Compilation message

insects.cpp: In function 'bool check(int, int)':
insects.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (int i = 0; i < inside.size(); i++) move_outside(inside[i]);
      |                   ~~^~~~~~~~~~~~~~~
insects.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 0; i < outside.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~
insects.cpp:88:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for (int i = 0; i < first.size() && !res; i++) {
      |                   ~~^~~~~~~~~~~~~~
insects.cpp:96:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   for (int i = 0; i < outside2.size(); i++) move_outside(outside2[i]);
      |                   ~~^~~~~~~~~~~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:111:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |   for (int i = 0; i < first.size(); i++) move_outside(first[i]);
      |                   ~~^~~~~~~~~~~~~~
insects.cpp:114:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  114 |   if (first.size() > N/2) return 1;
      |       ~~~~~~~~~~~~~^~~~~
# 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 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 9 ms 600 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 10 ms 600 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 7 ms 436 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 1 ms 344 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 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 9 ms 600 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 10 ms 600 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 7 ms 436 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 6 ms 860 KB Output is correct
25 Correct 44 ms 1420 KB Output is correct
26 Correct 58 ms 856 KB Output is correct
27 Correct 52 ms 856 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 49 ms 932 KB Output is correct
30 Correct 45 ms 920 KB Output is correct
31 Correct 41 ms 1176 KB Output is correct
32 Correct 52 ms 1428 KB Output is correct
33 Correct 52 ms 1176 KB Output is correct
34 Correct 54 ms 1344 KB Output is correct
35 Correct 55 ms 1172 KB Output is correct
36 Correct 51 ms 1096 KB Output is correct
37 Correct 54 ms 1160 KB Output is correct
38 Correct 55 ms 924 KB Output is correct
39 Correct 44 ms 1088 KB Output is correct
40 Correct 46 ms 928 KB Output is correct
41 Correct 4 ms 692 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 Partially correct 0 ms 344 KB Output is partially correct
6 Partially correct 0 ms 344 KB Output is partially correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 8 ms 600 KB Output is correct
9 Partially correct 118 ms 1144 KB Output is partially correct
10 Partially correct 131 ms 932 KB Output is partially correct
11 Partially correct 100 ms 680 KB Output is partially correct
12 Partially correct 99 ms 696 KB Output is partially correct
13 Partially correct 132 ms 688 KB Output is partially correct
14 Partially correct 109 ms 904 KB Output is partially correct
15 Partially correct 109 ms 668 KB Output is partially correct
16 Partially correct 114 ms 668 KB Output is partially correct
17 Partially correct 114 ms 896 KB Output is partially correct
18 Partially correct 110 ms 1112 KB Output is partially correct
19 Partially correct 122 ms 676 KB Output is partially correct
20 Partially correct 118 ms 908 KB Output is partially correct
21 Partially correct 131 ms 916 KB Output is partially correct
22 Partially correct 132 ms 692 KB Output is partially correct
23 Partially correct 115 ms 648 KB Output is partially correct
24 Partially correct 113 ms 916 KB Output is partially correct
25 Partially correct 115 ms 912 KB Output is partially correct
26 Correct 8 ms 680 KB Output is correct
27 Partially correct 103 ms 912 KB Output is partially correct
28 Partially correct 99 ms 912 KB Output is partially correct
29 Partially correct 102 ms 892 KB Output is partially correct
30 Partially correct 103 ms 672 KB Output is partially correct
31 Partially correct 120 ms 924 KB Output is partially correct
32 Partially correct 120 ms 688 KB Output is partially correct
33 Partially correct 127 ms 900 KB Output is partially correct
34 Partially correct 119 ms 600 KB Output is partially correct
35 Partially correct 111 ms 424 KB Output is partially correct
36 Partially correct 109 ms 852 KB Output is partially correct
37 Partially correct 123 ms 916 KB Output is partially correct
38 Partially correct 131 ms 1176 KB Output is partially correct
39 Partially correct 116 ms 1056 KB Output is partially correct
40 Partially correct 106 ms 900 KB Output is partially correct
41 Partially correct 115 ms 1136 KB Output is partially correct
42 Partially correct 105 ms 1160 KB Output is partially correct
43 Partially correct 27 ms 436 KB Output is partially correct
44 Partially correct 106 ms 844 KB Output is partially correct
45 Partially correct 53 ms 904 KB Output is partially correct
46 Partially correct 101 ms 1168 KB Output is partially correct
47 Partially correct 109 ms 1104 KB Output is partially correct
48 Partially correct 94 ms 1100 KB Output is partially correct