제출 #800573

#제출 시각아이디문제언어결과실행 시간메모리
800573d4xn드문 곤충 (IOI22_insects)C++17
0 / 100
262 ms328 KiB
#include "insects.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) x.begin(), x.end()
 
const int N = 2e3+3, inf = INT_MAX;
 
mt19937 rng((chrono::steady_clock::now().time_since_epoch().count()) + ((uint64_t) new char));
 
int n, mx, taken, ans, tp[N];
vector<int> v, f;
 
int min_cardinality(int N) {
  // move_inside(i);
  // move_outside(i);
  // press_button(i);
 
  memset(tp, -1, sizeof(tp));
  ans = inf;
  n = N;
  v.resize(n);
  for (int i = 0; i < n; i++) v[i] = i;
 
  // en el primer for los meto todos y intento identificar los que son iguales al primero
  // y los primeros (si el max es 1 y despues de añadir sigue siendo 1, es un primero)
  // quiero saber cuanto vale max
  shuffle(all(v), rng);
 
  mx = 1;
  int extra = 0;
  bool ok = 1;
 
  move_inside(v[0]);
  f.push_back(v[0]);
  tp[v[0]] = 0;
 
  for (int i = 1; i < n; i++) {
    int x = v[i];
    move_inside(x);
    mx = press_button();
 
    if (ok && mx == i+1) {
      tp[x] = 0;
      extra++;
    }
    else {
      ok = 0;
      if (mx == 1) {
        tp[x] = tp[f.back()]+1;
        f.push_back(x);
      }
    }
  }
 
  // quito los no primeros
  int curr = 0;
  for (int i = 0; i < n; i++) {
    int x = v[i];
    if (curr < (int)f.size() && f[curr] == x) {
      curr++;
      continue;
    }
    move_outside(x);
  }
 
  // primer for y ver cuantos son iguales al primero
  shuffle(all(v), rng);
  for (int i = 0; i < n; i++) {
    int x = v[i];
    if (tp[x] != -1) continue;
 
    move_inside(x);
    if (press_button() > 1) {
      move_outside(x);
    }
    else {
      tp[x] = tp[f.back()]+1;
      f.push_back(x);
    }
  }
  taken = f.size();
 
  // miro cada grupo
  for (int t = 0; t < (int)f.size(); t++) {
    shuffle(all(v), rng);
 
    mx = min(mx, n-taken+1);
  
    if (t) extra = 0;
    
    curr = 1; // cuantos he metido?
    vector<int> added;
    for (int i = 0; i < n && curr+extra < mx && curr+extra < ans; i++) {
      int x = v[i];
      if (tp[x] != -1) continue;
      
      move_inside(x);
      if (press_button() == curr+1) {
        tp[x] = t;
        added.push_back(x);
        curr++;
      }
      else {
        move_outside(x);
      }
    }
 
    for (int& x : added) {
      move_outside(x);
    }
 
    ans = min(ans, curr+extra);
    taken += curr+extra-1;
  }
 
  return ans;
  
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...