답안 #1074645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074645 2024-08-25T11:39:32 Z fv3 드문 곤충 (IOI22_insects) C++17
0 / 100
2000 ms 344 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

int min_cardinality(int N) 
{
  // Find the number of different insect types:
  // Maximum number of insects with 1 being maximum
  // Let that number be K
  // Find another set of K numbers with 2 being the maximum
  // Then 3 and 4 and so on untill it is no longer possible

  // The grader is not adaptive:
  vector<int> indicies(N);
  iota(indicies.begin(), indicies.end(), 0);

  mt19937 mt(time(0));
  shuffle(indicies.begin(), indicies.end(), mt);

  vector<int> in(N), group(N);

  int k = 0; // N
  for (int i = 0; i < N; i++)
  {
    move_inside(indicies[i]);
    if (press_button() > 1)
    {
      move_outside(indicies[i]);
    }
    else
    {
      k++;
      in[i] = 2;
      group[i] = 1;
    }
  }

  // Split into two groups: N
  int cnt = 0;
  vector<int> g2;
  for (int i = 0; i < N && cnt < k / 2; i++)
  {
    if (!in[i]) continue;
    cnt++;
    g2.push_back(i);
    group[i] = 2;
    move_outside(indicies[i]);
  }

  for (int i = 0; i < N; i++)
  {
    if (in[i]) continue;
    move_inside(indicies[i]);
    if (press_button() > 1)
      group[i] = 1;
    else
      group[i] = 2;
    move_outside(indicies[i]);
  }

  int res1 = 1;
  while (true)
  {
    int cnt = 0;
    for (int i = 0; i < N && cnt < k / 2; i++)
    {
      if (in[i] || group[i] == 2) continue;
      move_inside(indicies[i]);
      if (press_button() > res1 + 1)
      {
        move_outside(indicies[i]);
      }
      else
      {
        cnt++;
        in[i] = 1;
      }
    }

    if (cnt < k / 2)
      break;
    res1++;
  }

  for (int i = 0; i < N; i++)
  {
    if (!in[i]) continue;
    if (in[i] == 2) continue;
    move_outside(indicies[i]);
    in[i] = 0;
  }

  for (auto e : g2)
  {
    in[e] = 1;
    move_inside(indicies[e]);
  }

  int res2 = 1;
  while (true)
  {
    int cnt = 0;
    for (int i = 0; i < N && cnt < (k + 1) / 2; i++)
    {
      if (in[i] || group[i] == 1) continue;
      move_inside(indicies[i]);
      if (press_button() > res2 + 1)
      {
        move_outside(indicies[i]);
      }
      else
      {
        cnt++;
        in[i] = 1;
      }
    }

    if (cnt < (k + 1) / 2)
      break;
    res2++;
  }

  return min(res1, res2);
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3061 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3061 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3086 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -