Submission #627858

# Submission time Handle Problem Language Result Execution time Memory
627858 2022-08-13T00:15:13 Z Fischer Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;

const int maxn = 2010;
int in[maxn];
vector<bool> memo;
int n, c;
int base;
vector<int> id;

void put(int x) {
  move_inside(x);
  //memo[x] = 1;
}

void pop(int x) {
  move_outside(x);
  //memo[x] = 0;
}

map<vector<bool>, int> mapMemo;
bool last[maxn];
int push() {
  return press_button();
  
  if (mapMemo.count(memo)) return mapMemo[memo];

  for (int i = 0; i < n; ++i) {
    if (last[i] != (in[i] != 0)) {
      if (last[i]) move_outside(i);
      else move_inside(i);
      last[i] ^= 1;
    } 
  }

  return mapMemo[memo] = press_button();
}

bool p(int x) {  
  int len = base;
  for (int i:id) {
    if (in[i] == -1) continue;
    if (len == x * c) break;
    put(i);
    in[i] = 1;
    if (push() > x) {
      pop(i);
      in[i] = 0;
    } else {
      len += 1;
    }
  }

  if (len == x * c) {
    for (int i:id) {
      if (in[i] == 1) {
        in[i] = -1;
        base += 1;
      }
    }
  } else {
    for (int i:id) {
      if (in[i] == 1) {
        pop(i);
        in[i] = 0;
      }
    }
  }

  return len == x * c;
}

int min_cardinality(int N) {
  n = N;
  id.resize(n);
  iota(id.begin(), id.end());
  random_shuffle(id.begin(), id.end());
  memo.assign(n, 0);
  c = 0;  
  for (int i:id) {
      put(i);
      in[i] = -1;
      if (push() == 1) c += 1;
      else pop(i), in[i] = 0; 
  }
  base = c;

  if (c == 1) return N;
  if (c == N) return 1;

  int lo = 1, hi = N / c+1;
  while (hi-lo>1) {
    int mid = (lo + hi) / 2;
    if (p(mid)) lo = mid;
    else hi = mid;
  }

  return lo;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:77:28: error: no matching function for call to 'iota(std::vector<int>::iterator, std::vector<int>::iterator)'
   77 |   iota(id.begin(), id.end());
      |                            ^
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from insects.cpp:1:
/usr/include/c++/10/bits/stl_numeric.h:88:5: note: candidate: 'template<class _ForwardIterator, class _Tp> void std::iota(_ForwardIterator, _ForwardIterator, _Tp)'
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
/usr/include/c++/10/bits/stl_numeric.h:88:5: note:   template argument deduction/substitution failed:
insects.cpp:77:28: note:   candidate expects 3 arguments, 2 provided
   77 |   iota(id.begin(), id.end());
      |                            ^