Submission #629588

#TimeUsernameProblemLanguageResultExecution timeMemory
629588flashmt드문 곤충 (IOI22_insects)C++17
99.82 / 100
64 ms448 KiB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

pair<vector<int>, vector<int>> findFirstOccurrences(vector<int> id, int maxC, int expectedSize)
{
  vector<int> good, bad;
  shuffle(begin(id), end(id), rng);
  for (int i : id)
  {
    if (size(good) == expectedSize)
    {
      bad.push_back(i);
      continue;
    }

    move_inside(i);
    if (press_button() <= maxC) good.push_back(i);
    else
    {
      move_outside(i);
      bad.push_back(i);
    }
  }
  for (int i : good)
    move_outside(i);
  return {good, bad};
}

int min_cardinality(int n)
{
  vector<int> id(n);
  iota(begin(id), end(id), 0);
  auto [good, bad] = findFirstOccurrences(id, 1, n);
  int typeCnt = size(good);

  int low = 2, high = n / typeCnt, ans = 1;
  id = bad;
  while (low <= high)
  {
    int mid = (low + high + 1) / 2;
    int expectedSize = typeCnt * (mid - ans);
    tie(good, bad) = findFirstOccurrences(id, mid - ans, expectedSize);
    if (size(good) == expectedSize)
    {
      ans = mid;
      low = mid + 1;
      id = bad;
    }
    else
    {
      high = min(mid - 1, int(size(good)) / typeCnt + ans);
      id = good;
    }
  }
  return ans;
}

Compilation message (stderr)

insects.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > findFirstOccurrences(std::vector<int>, int, int)':
insects.cpp:13:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |     if (size(good) == expectedSize)
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:46:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |     if (size(good) == expectedSize)
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...