답안 #1078229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078229 2024-08-27T14:16:51 Z Faisal_Saqib 드문 곤충 (IOI22_insects) C++17
92.99 / 100
436 ms 21788 KB
#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
set<int> machine,rem;
int sm=0;
void add(int x)
{
	if(machine.find(x)==machine.end())
	{
		move_inside(x);
		machine.insert(x);
	}
}
void remp(int x)
{
	if(machine.find(x)!=machine.end())
	{
		move_outside(x);
		machine.erase(x);
	}
}
map<vector<int>,int> store;
int ask()
{
	vector<int> cur(begin(machine),end(machine));
	if(store.find(cur)==store.end())
		store[cur]=press_button();
	// cout<<"Query for: ";
	// for(auto j:cur)
	// {
	// 	cout<<j<<' ';
	// }
	// cout<<" ans: "<<store[cur]<<endl;
	return store[cur];
}
int min_cardinality(int n)
{
	add(0);
	for(int i=1;i<n;i++)
	{
		add(i);
		if(ask()>1)
		{
			rem.insert(i);
			remp(i);
		}
	}
	int sz=machine.size();
	int s=1;
	int e=(n/sz)+1;
	while(s+1<e)
	{
		int mid=(s+e)/2;
		vector<int> cur;
		// cout<<endl;
		// cout<<"for "<<mid<<endl;
		// cout<<"\nMachine: ";
		// for(auto j:machine)
		// {
		// 	cout<<j<<' ';
		// }
		// cout<<endl;
		for(auto i:rem)
		{
			// cout<<"Add and query "<<i<<endl;
			add(i);
			if(ask()>mid)
			{
				remp(i);
			}
			else
			{
				cur.push_back(i);
				if(machine.size()==(sz*mid))
					break;
			}
		}
		if(machine.size()==((sz*mid)))
		{
			s=mid;
			//	 We can make values in amachin so keep
			for(auto i:cur)
				rem.erase(i);
		}
		else{
			e=mid;
			rem.clear();
			for(auto i:machine)
				rem.insert(i);
			for(auto i:rem)
				remp(i);
		}
	}
	return s;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:76:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |     if(machine.size()==(sz*mid))
      |        ~~~~~~~~~~~~~~^~~~~~~~~~
insects.cpp:80:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |   if(machine.size()==((sz*mid)))
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 452 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 5 ms 772 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 7 ms 640 KB Output is correct
16 Correct 8 ms 600 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 5 ms 856 KB Output is correct
19 Correct 8 ms 600 KB Output is correct
20 Correct 4 ms 532 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 452 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 5 ms 772 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 7 ms 640 KB Output is correct
16 Correct 8 ms 600 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 5 ms 856 KB Output is correct
19 Correct 8 ms 600 KB Output is correct
20 Correct 4 ms 532 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 33 ms 3064 KB Output is correct
24 Correct 33 ms 2980 KB Output is correct
25 Correct 72 ms 3896 KB Output is correct
26 Correct 100 ms 6064 KB Output is correct
27 Correct 42 ms 1616 KB Output is correct
28 Correct 22 ms 1560 KB Output is correct
29 Correct 48 ms 2308 KB Output is correct
30 Correct 42 ms 2896 KB Output is correct
31 Correct 65 ms 4552 KB Output is correct
32 Correct 138 ms 6240 KB Output is correct
33 Correct 115 ms 5712 KB Output is correct
34 Correct 74 ms 4724 KB Output is correct
35 Correct 79 ms 4812 KB Output is correct
36 Correct 69 ms 4284 KB Output is correct
37 Correct 69 ms 4712 KB Output is correct
38 Correct 49 ms 3172 KB Output is correct
39 Correct 48 ms 3148 KB Output is correct
40 Correct 35 ms 3004 KB Output is correct
41 Correct 28 ms 2088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 112 ms 10564 KB Output is correct
8 Correct 117 ms 10320 KB Output is correct
9 Correct 203 ms 15184 KB Output is correct
10 Partially correct 342 ms 20124 KB Output is partially correct
11 Correct 81 ms 4688 KB Output is correct
12 Correct 107 ms 8972 KB Output is correct
13 Correct 125 ms 7276 KB Output is correct
14 Correct 161 ms 8960 KB Output is correct
15 Partially correct 368 ms 17284 KB Output is partially correct
16 Partially correct 436 ms 19288 KB Output is partially correct
17 Partially correct 333 ms 17352 KB Output is partially correct
18 Partially correct 395 ms 19676 KB Output is partially correct
19 Partially correct 318 ms 18376 KB Output is partially correct
20 Partially correct 374 ms 20760 KB Output is partially correct
21 Partially correct 347 ms 17964 KB Output is partially correct
22 Correct 254 ms 12920 KB Output is correct
23 Correct 189 ms 9912 KB Output is correct
24 Correct 242 ms 13376 KB Output is correct
25 Correct 182 ms 11580 KB Output is correct
26 Correct 92 ms 6992 KB Output is correct
27 Correct 310 ms 19468 KB Output is correct
28 Correct 149 ms 10184 KB Output is correct
29 Correct 390 ms 20796 KB Output is correct
30 Correct 315 ms 20944 KB Output is correct
31 Partially correct 307 ms 16064 KB Output is partially correct
32 Partially correct 340 ms 19244 KB Output is partially correct
33 Correct 165 ms 9288 KB Output is correct
34 Correct 132 ms 9908 KB Output is correct
35 Partially correct 319 ms 21072 KB Output is partially correct
36 Correct 256 ms 16376 KB Output is correct
37 Partially correct 333 ms 16468 KB Output is partially correct
38 Partially correct 341 ms 18124 KB Output is partially correct
39 Correct 323 ms 19604 KB Output is correct
40 Correct 112 ms 10296 KB Output is correct
41 Correct 249 ms 17012 KB Output is correct
42 Partially correct 320 ms 21788 KB Output is partially correct
43 Correct 11 ms 856 KB Output is correct
44 Correct 51 ms 3056 KB Output is correct
45 Correct 171 ms 11092 KB Output is correct
46 Correct 59 ms 6956 KB Output is correct
47 Correct 158 ms 10576 KB Output is correct
48 Correct 108 ms 9000 KB Output is correct