Submission #1335737

#TimeUsernameProblemLanguageResultExecution timeMemory
1335737sporknivesRarest Insects (IOI22_insects)C++20
Compilation error
0 ms0 KiB
int min_cardinality(int N) {
	int d = 0;
	bool marked[N]; memset(marked,false,sizeof(marked));
	set<int> s;
	vector<int> to_remove;
	for(int i=0;i<N;i++) {
		if(s.find(i)==s.end()){
			move_inside(i);
			s.insert(i);
		}
		int res = press_button();
		if(res>1) {
			if(s.find(i)!=s.end()){
				move_outside(i);
				s.erase(i);
			}
		}
		else {
			d++;
		}
	}
	
	int ans = 0;
	int lo=1,hi=N/d;
	while(lo<=hi) {
		int mid = (lo+hi)/2;
		to_remove.clear();
		vector<int> to_mark;
		int cnt=0;
		for(int i=0;i<N;i++) {
			if(marked[i])continue;
			if(s.find(i)==s.end()){
				move_inside(i);
				s.insert(i);
				 
				int res = press_button();
				if(res > mid) {
					if(s.find(i)!=s.end()) {
						move_outside(i);
						s.erase(i);
						to_mark.push_back(i);
					}
				}
				else {
					cnt++;
					to_remove.push_back(i);
				}
			}
			else cnt++;
		}
		if(cnt==d*mid) {
			lo=mid+1;
			ans=max(ans,mid);
		}
		else {
			hi=mid-1;
			for(int x: to_remove) {
				if(s.find(x)!=s.end()) {
					move_outside(x);
					s.erase(x);
				}
			}
			for(int x: to_mark) marked[x]=true;
		}
	}
	
	return ans;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:3:25: error: 'memset' was not declared in this scope
    3 |         bool marked[N]; memset(marked,false,sizeof(marked));
      |                         ^~~~~~
insects.cpp:1:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
  +++ |+#include <cstring>
    1 | int min_cardinality(int N) {
insects.cpp:4:9: error: 'set' was not declared in this scope
    4 |         set<int> s;
      |         ^~~
insects.cpp:4:13: error: expected primary-expression before 'int'
    4 |         set<int> s;
      |             ^~~
insects.cpp:5:9: error: 'vector' was not declared in this scope
    5 |         vector<int> to_remove;
      |         ^~~~~~
insects.cpp:5:16: error: expected primary-expression before 'int'
    5 |         vector<int> to_remove;
      |                ^~~
insects.cpp:7:20: error: 's' was not declared in this scope
    7 |                 if(s.find(i)==s.end()){
      |                    ^
insects.cpp:8:25: error: 'move_inside' was not declared in this scope
    8 |                         move_inside(i);
      |                         ^~~~~~~~~~~
insects.cpp:11:27: error: 'press_button' was not declared in this scope
   11 |                 int res = press_button();
      |                           ^~~~~~~~~~~~
insects.cpp:13:28: error: 's' was not declared in this scope
   13 |                         if(s.find(i)!=s.end()){
      |                            ^
insects.cpp:14:33: error: 'move_outside' was not declared in this scope
   14 |                                 move_outside(i);
      |                                 ^~~~~~~~~~~~
insects.cpp:27:17: error: 'to_remove' was not declared in this scope
   27 |                 to_remove.clear();
      |                 ^~~~~~~~~
insects.cpp:28:24: error: expected primary-expression before 'int'
   28 |                 vector<int> to_mark;
      |                        ^~~
insects.cpp:32:28: error: 's' was not declared in this scope
   32 |                         if(s.find(i)==s.end()){
      |                            ^
insects.cpp:33:33: error: 'move_inside' was not declared in this scope
   33 |                                 move_inside(i);
      |                                 ^~~~~~~~~~~
insects.cpp:36:43: error: 'press_button' was not declared in this scope
   36 |                                 int res = press_button();
      |                                           ^~~~~~~~~~~~
insects.cpp:39:49: error: 'move_outside' was not declared in this scope
   39 |                                                 move_outside(i);
      |                                                 ^~~~~~~~~~~~
insects.cpp:41:49: error: 'to_mark' was not declared in this scope
   41 |                                                 to_mark.push_back(i);
      |                                                 ^~~~~~~
insects.cpp:53:29: error: 'max' was not declared in this scope
   53 |                         ans=max(ans,mid);
      |                             ^~~
insects.cpp:58:36: error: 's' was not declared in this scope
   58 |                                 if(s.find(x)!=s.end()) {
      |                                    ^
insects.cpp:59:41: error: 'move_outside' was not declared in this scope
   59 |                                         move_outside(x);
      |                                         ^~~~~~~~~~~~
insects.cpp:63:36: error: 'to_mark' was not declared in this scope
   63 |                         for(int x: to_mark) marked[x]=true;
      |                                    ^~~~~~~