Submission #631842

# Submission time Handle Problem Language Result Execution time Memory
631842 2022-08-19T00:28:39 Z jwvg0425 Rarest Insects (IOI22_insects) C++17
100 / 100
60 ms 560 KB
#include "insects.h"
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

template<typename T, typename Pr = less<T>>
using pq = priority_queue<T, vector<T>, Pr>;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int min_cardinality(int n)
{
	// i번 원소는 각 집합에서 l[i]번째 이상 r[i]번째 이하 원소임(맨왼쪽부터 그 집합 순서대로 다 포함시켰을때)
	vector<int> l(n, 1);
	vector<int> r(n, n);

	set<int> sel;

	for (int i = 0; i < n; i++)
	{
		move_inside(i);
		if (press_button() > 1)
		{
			l[i] = 2;
			move_outside(i);
			continue;
		}

		r[i] = 1;
		sel.insert(i);
	}

	int group = sel.size();

	int now = 1;
	int lo = 1, hi = n / group;
	int ans = n;

	while (lo <= hi)
	{
		int mid = (lo + hi + 1) / 2;

		set<int> noSel;

		for (auto& si : sel)
		{
			if (r[si] > mid)
				noSel.insert(si);
		}

		for (auto& no : noSel)
		{
			move_outside(no);
			sel.erase(no);
		}

		now = press_button();

		for (int i = 0; i < n; i++)
		{
			if (sel.find(i) != sel.end() || l[i] > mid)
				continue;

			move_inside(i);

			int x = press_button();
			if (x > mid)
			{
				l[i] = x;
				move_outside(i);
				continue;
			}

			sel.insert(i);
			if (x > now)
			{
				l[i] = r[i] = x;
				now = x;
			}
			else
			{
				// 최소한 now번째 이하임
				r[i] = min(r[i], now);
			}
		}

		if (sel.size() == group * mid)
		{
			ans = mid;
			lo = mid + 1;
		}
		else
		{
			hi = mid - 1;
		}
	}

	return ans;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:106:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |   if (sel.size() == group * mid)
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 308 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 308 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 4 ms 308 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 304 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 304 KB Output is correct
18 Correct 4 ms 308 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 308 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 308 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 4 ms 308 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 304 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 304 KB Output is correct
18 Correct 4 ms 308 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 300 KB Output is correct
23 Correct 19 ms 308 KB Output is correct
24 Correct 9 ms 340 KB Output is correct
25 Correct 23 ms 328 KB Output is correct
26 Correct 21 ms 296 KB Output is correct
27 Correct 15 ms 308 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 23 ms 304 KB Output is correct
30 Correct 29 ms 328 KB Output is correct
31 Correct 29 ms 308 KB Output is correct
32 Correct 30 ms 320 KB Output is correct
33 Correct 30 ms 284 KB Output is correct
34 Correct 25 ms 300 KB Output is correct
35 Correct 23 ms 308 KB Output is correct
36 Correct 28 ms 320 KB Output is correct
37 Correct 19 ms 320 KB Output is correct
38 Correct 18 ms 304 KB Output is correct
39 Correct 16 ms 304 KB Output is correct
40 Correct 20 ms 320 KB Output is correct
41 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 42 ms 372 KB Output is correct
8 Correct 16 ms 348 KB Output is correct
9 Correct 60 ms 356 KB Output is correct
10 Correct 32 ms 300 KB Output is correct
11 Correct 25 ms 320 KB Output is correct
12 Correct 26 ms 324 KB Output is correct
13 Correct 45 ms 328 KB Output is correct
14 Correct 38 ms 300 KB Output is correct
15 Correct 51 ms 308 KB Output is correct
16 Correct 59 ms 348 KB Output is correct
17 Correct 47 ms 364 KB Output is correct
18 Correct 53 ms 368 KB Output is correct
19 Correct 59 ms 364 KB Output is correct
20 Correct 48 ms 304 KB Output is correct
21 Correct 52 ms 308 KB Output is correct
22 Correct 55 ms 312 KB Output is correct
23 Correct 60 ms 340 KB Output is correct
24 Correct 32 ms 320 KB Output is correct
25 Correct 22 ms 316 KB Output is correct
26 Correct 22 ms 344 KB Output is correct
27 Correct 52 ms 304 KB Output is correct
28 Correct 42 ms 356 KB Output is correct
29 Correct 45 ms 292 KB Output is correct
30 Correct 34 ms 560 KB Output is correct
31 Correct 46 ms 312 KB Output is correct
32 Correct 47 ms 308 KB Output is correct
33 Correct 40 ms 300 KB Output is correct
34 Correct 41 ms 328 KB Output is correct
35 Correct 45 ms 328 KB Output is correct
36 Correct 38 ms 440 KB Output is correct
37 Correct 45 ms 356 KB Output is correct
38 Correct 44 ms 300 KB Output is correct
39 Correct 45 ms 432 KB Output is correct
40 Correct 60 ms 296 KB Output is correct
41 Correct 48 ms 424 KB Output is correct
42 Correct 50 ms 380 KB Output is correct
43 Correct 10 ms 304 KB Output is correct
44 Correct 36 ms 312 KB Output is correct
45 Correct 47 ms 328 KB Output is correct
46 Correct 14 ms 328 KB Output is correct
47 Correct 26 ms 340 KB Output is correct
48 Correct 28 ms 328 KB Output is correct