답안 #633173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633173 2022-08-21T18:28:37 Z Joshua_Andersson 드문 곤충 (IOI22_insects) C++17
83.97 / 100
102 ms 556 KB
#include <bits/stdc++.h>
using namespace std;


typedef pair<int, int> p2;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<p2> vp2;

#define rep(var,high) for(int var=0;var<high;var++)
#define repe(var,container) for(auto& var : container)

#define local 0

#if local
int N = 8;
map<int, int> insidemachine;
bool hasinit = false;
vi bois(N);
void init()
{
	return;
	if (hasinit) return;
	hasinit = true;
	//rep(i, N) bois[i] = rand() % N;
	bois[0] = 1;
	bois[1] = 1;
	bois[2] = 1;
	bois[3] = 2;
	bois[4] = 2;
	bois[5] = 2;
	bois[6] = 2;
	bois[7] = 2;
}
void move_inside(int i) { init(); insidemachine[bois[i]]++; }
void move_outside(int i) { if (insidemachine[bois[i]]) insidemachine[bois[i]]--; }
int press_button()
{
	int ret = 0;
	repe(el, insidemachine)	ret = max(ret, el.second);
	return ret;
}

int judgeans()
{
	int ret = 100000000;
	repe(el, insidemachine)	if (el.second!=0) ret = min(ret, el.second);
	return ret;
}
#else
void move_inside(int i);
void move_outside(int i);
int press_button();
#endif


int min_cardinality(int n)
{


	int col = 0;

	vi inside(n);

	int types = 0;

	rep(i, n)
	{
		
		move_inside(i);
		inside[i] = true;
		types++;

		if (press_button() > 1)
		{
			move_outside(i);
			inside[i] = false;
			types--;
		}
	}
	rep(i, n) if (inside[i]) move_outside(i);
	if (types == 1) return n;

	int high = n;
	int low = 1;

	vi isinside(n);
	int insidemaballs = 0;

	set<int> possible;
	rep(i, n) possible.insert(i);

	while (true)
	{
		int x = (high + low) / 2;
		bool works = false;
		if (n>=types*x)
		{
			

			repe(i, possible)
			{
				if (isinside[i]) continue;
				move_inside(i);
				isinside[i] = true;

				insidemaballs++;

				if (press_button() > x)
				{
					move_outside(i);
					isinside[i] = false;
					insidemaballs--;
				}

				if (insidemaballs>=types*x)
				{
					break;
				}
			}
			
			if (insidemaballs == types * x) works = true;

			if (works)
			{
				// Keep insects inside
			}
			if (!works)
			{
				rep(i, n)
				{
					if (!isinside[i])
					{
						possible.erase(i);
					}
					else
					{
						move_outside(i);
					}
				}
				isinside = vi(n, false);
				insidemaballs = 0;
			}
		}
		
		

		// If they are all greater than or equal to ans, the answer is larger than x
		
		if (works)
		{
			low = x;
		}
		else
		{
			high = x;
		}

		if (low+1==high)
		{
			return low;
		}
	}

	//return colorcnt[0];
}

#if local
int main()
{
	rep(i, 100000)
	{
		N = 2+rand() % 100;
		//bois = { 2, 0, 0 ,0 ,2 ,0 ,0 };
		//N = bois.size();
		bois=vi(N);
		rep(i, N) bois[i] = rand() % N;
		insidemachine = map<int, int>();

		rep(i, N) insidemachine[bois[i]]++;
		int jans = 100000000;
		repe(el, insidemachine)	if (el.second != 0) jans = min(jans, el.second);
		insidemachine = map<int, int>();
		

		if (min_cardinality(N)!=jans)
		{
			cout << "ligma:; ";
			rep(i, N)
			{
				cout << bois[i] << ", ";
			}
			cout << "\n\n";
			__debugbreak();
		}
	}
}
#endif

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:61:6: warning: unused variable 'col' [-Wunused-variable]
   61 |  int col = 0;
      |      ^~~
# 결과 실행 시간 메모리 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 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 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 7 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 6 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 8 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 7 ms 300 KB Output is correct
19 Correct 3 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 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 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 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 7 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 6 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 8 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 7 ms 300 KB Output is correct
19 Correct 3 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 296 KB Output is correct
23 Correct 11 ms 208 KB Output is correct
24 Correct 10 ms 336 KB Output is correct
25 Correct 16 ms 328 KB Output is correct
26 Correct 44 ms 336 KB Output is correct
27 Correct 25 ms 296 KB Output is correct
28 Correct 8 ms 296 KB Output is correct
29 Correct 31 ms 328 KB Output is correct
30 Correct 30 ms 340 KB Output is correct
31 Correct 36 ms 340 KB Output is correct
32 Correct 54 ms 556 KB Output is correct
33 Correct 47 ms 280 KB Output is correct
34 Correct 50 ms 296 KB Output is correct
35 Correct 27 ms 296 KB Output is correct
36 Correct 38 ms 328 KB Output is correct
37 Correct 39 ms 332 KB Output is correct
38 Correct 34 ms 336 KB Output is correct
39 Correct 28 ms 336 KB Output is correct
40 Correct 8 ms 300 KB Output is correct
41 Correct 9 ms 300 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 20 ms 208 KB Output is correct
8 Correct 27 ms 300 KB Output is correct
9 Correct 41 ms 328 KB Output is correct
10 Partially correct 68 ms 284 KB Output is partially correct
11 Partially correct 69 ms 284 KB Output is partially correct
12 Correct 40 ms 288 KB Output is correct
13 Partially correct 60 ms 296 KB Output is partially correct
14 Partially correct 49 ms 388 KB Output is partially correct
15 Partially correct 88 ms 388 KB Output is partially correct
16 Partially correct 79 ms 388 KB Output is partially correct
17 Partially correct 102 ms 396 KB Output is partially correct
18 Partially correct 84 ms 508 KB Output is partially correct
19 Partially correct 75 ms 388 KB Output is partially correct
20 Partially correct 71 ms 396 KB Output is partially correct
21 Partially correct 80 ms 412 KB Output is partially correct
22 Partially correct 62 ms 392 KB Output is partially correct
23 Partially correct 58 ms 388 KB Output is partially correct
24 Correct 48 ms 388 KB Output is correct
25 Correct 42 ms 300 KB Output is correct
26 Correct 18 ms 300 KB Output is correct
27 Correct 44 ms 296 KB Output is correct
28 Correct 38 ms 300 KB Output is correct
29 Partially correct 55 ms 432 KB Output is partially correct
30 Partially correct 48 ms 300 KB Output is partially correct
31 Partially correct 66 ms 412 KB Output is partially correct
32 Partially correct 90 ms 484 KB Output is partially correct
33 Partially correct 47 ms 328 KB Output is partially correct
34 Partially correct 75 ms 296 KB Output is partially correct
35 Correct 33 ms 384 KB Output is correct
36 Correct 41 ms 288 KB Output is correct
37 Partially correct 81 ms 416 KB Output is partially correct
38 Partially correct 84 ms 400 KB Output is partially correct
39 Correct 45 ms 300 KB Output is correct
40 Correct 37 ms 288 KB Output is correct
41 Correct 35 ms 328 KB Output is correct
42 Correct 29 ms 300 KB Output is correct
43 Correct 14 ms 208 KB Output is correct
44 Correct 42 ms 392 KB Output is correct
45 Correct 45 ms 284 KB Output is correct
46 Correct 44 ms 304 KB Output is correct
47 Correct 35 ms 296 KB Output is correct
48 Correct 39 ms 288 KB Output is correct