답안 #629611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629611 2022-08-14T18:14:41 Z flashmt 드문 곤충 (IOI22_insects) C++17
100 / 100
63 ms 444 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;

pair<vector<int>, vector<int>> findFirstOccurrences(vector<int> id, int maxC, int expectedSize)
{
  vector<int> good, bad;
  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 ans = 1;
  id = bad;
  while (size(id) >= typeCnt)
  {
    int low = 1, high = size(id) / typeCnt, rem = size(id) % typeCnt;
    int mid = (low + high + (rem * 2 > typeCnt)) / 2;
    int expectedSize = typeCnt * mid;
    tie(good, bad) = findFirstOccurrences(id, mid, expectedSize);
    if (size(good) < expectedSize) id = good;
    else
    {
      ans += mid;
      id = bad;
    }
  }
  return ans;
}

Compilation message

insects.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > findFirstOccurrences(std::vector<int>, int, int)':
insects.cpp:10:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   10 |     if (size(good) == expectedSize)
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:38:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |   while (size(id) >= typeCnt)
      |          ~~~~~~~~~^~~~~~~~~~
insects.cpp:44:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if (size(good) < expectedSize) id = good;
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 3 ms 296 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 2 ms 300 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 304 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 5 ms 300 KB Output is correct
21 Correct 5 ms 208 KB Output is correct
22 Correct 4 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 3 ms 296 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 2 ms 300 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 304 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 5 ms 300 KB Output is correct
21 Correct 5 ms 208 KB Output is correct
22 Correct 4 ms 296 KB Output is correct
23 Correct 14 ms 312 KB Output is correct
24 Correct 11 ms 316 KB Output is correct
25 Correct 23 ms 296 KB Output is correct
26 Correct 28 ms 296 KB Output is correct
27 Correct 17 ms 320 KB Output is correct
28 Correct 10 ms 312 KB Output is correct
29 Correct 25 ms 308 KB Output is correct
30 Correct 25 ms 208 KB Output is correct
31 Correct 22 ms 208 KB Output is correct
32 Correct 15 ms 208 KB Output is correct
33 Correct 23 ms 308 KB Output is correct
34 Correct 26 ms 208 KB Output is correct
35 Correct 24 ms 308 KB Output is correct
36 Correct 18 ms 308 KB Output is correct
37 Correct 22 ms 308 KB Output is correct
38 Correct 27 ms 312 KB Output is correct
39 Correct 17 ms 208 KB Output is correct
40 Correct 16 ms 304 KB Output is correct
41 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 41 ms 208 KB Output is correct
8 Correct 18 ms 324 KB Output is correct
9 Correct 33 ms 432 KB Output is correct
10 Correct 61 ms 316 KB Output is correct
11 Correct 36 ms 328 KB Output is correct
12 Correct 31 ms 208 KB Output is correct
13 Correct 48 ms 320 KB Output is correct
14 Correct 56 ms 208 KB Output is correct
15 Correct 28 ms 208 KB Output is correct
16 Correct 35 ms 328 KB Output is correct
17 Correct 18 ms 316 KB Output is correct
18 Correct 37 ms 208 KB Output is correct
19 Correct 47 ms 328 KB Output is correct
20 Correct 47 ms 316 KB Output is correct
21 Correct 63 ms 312 KB Output is correct
22 Correct 41 ms 316 KB Output is correct
23 Correct 53 ms 312 KB Output is correct
24 Correct 41 ms 208 KB Output is correct
25 Correct 25 ms 444 KB Output is correct
26 Correct 20 ms 320 KB Output is correct
27 Correct 56 ms 312 KB Output is correct
28 Correct 38 ms 320 KB Output is correct
29 Correct 55 ms 320 KB Output is correct
30 Correct 43 ms 312 KB Output is correct
31 Correct 44 ms 312 KB Output is correct
32 Correct 59 ms 328 KB Output is correct
33 Correct 47 ms 320 KB Output is correct
34 Correct 45 ms 316 KB Output is correct
35 Correct 55 ms 208 KB Output is correct
36 Correct 39 ms 324 KB Output is correct
37 Correct 48 ms 316 KB Output is correct
38 Correct 55 ms 320 KB Output is correct
39 Correct 51 ms 328 KB Output is correct
40 Correct 36 ms 312 KB Output is correct
41 Correct 36 ms 324 KB Output is correct
42 Correct 50 ms 316 KB Output is correct
43 Correct 13 ms 208 KB Output is correct
44 Correct 41 ms 320 KB Output is correct
45 Correct 30 ms 316 KB Output is correct
46 Correct 25 ms 320 KB Output is correct
47 Correct 30 ms 312 KB Output is correct
48 Correct 23 ms 208 KB Output is correct