답안 #988554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988554 2024-05-25T07:09:56 Z cnn008 드문 곤충 (IOI22_insects) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;

#include "insects.h"

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define ll long long

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    assert(l<=r);
    return uniform_int_distribution<int> (l,r)(rng);
}

const int N=1e5+5;
const int mod=1e9+7;

int min_cardinality(int n){
	set <int> s;
	// vector <int> nw;
	// vector <int> p(n);
	// iota(p.begin(),p.end(),0);
	// shuffle(p.begin(),p.end(),rng);
	map <int,set<int>> mp;
	int cad;
	auto add = [&](int i) -> void{
		s.insert(i);
		move_inside(i);
	};
	auto del = [&](int i) -> void{
		s.erase(i);
		move_outside(i);
	};
	auto clear = [&]() -> void{
		auto _s=s;
		for(auto i:_s) del(i);
	};
	// auto check = [&](int k) -> bool{
		// nw.clear();
		// auto op=*mp.lower_bound(k);
		// for(auto i:op.second){
			// if(s.find(i)!=s.end()) continue;
			// add(i);
			// if(press_button()>k) del(i);
			// else nw.push_back(i);
		// }
		// mp[k]=s;
		// return (int)s.size()>=cad*k;
	// };
	for(int i=0; i<n; i++){
		add(i);
		if(press_button()>1) del(i);
	}
	cad=(int)s.size();
	clear();
	if(cad<=9){
		vector <int> vis(n,0);
		int type=0;
		for(int i=0; i<n; i++){
			if(!vis[i]){
				vis[i]=++type;
				move_inside(i);
				for(int j=i+1; j<n; j++){
					move_inside(j);
					int val=press_button();
					if(val==2) vis[j]=type;
					move_outside(j);
				}
				move_outside(i);
			}
		}
		map <int,int> brute;
		for(int i=0; i<n; i++) brute[vis[i]]++;
		int ans=INT_MAX;
		for(auto [x,y]:brute) ans=min(ans,y);
		return ans;
	}
	mp[1]=s;
	for(int i=0; i<n; i++) mp[n].insert(i);
	int l=2,r=n/cad,ans=1;
	while(l<=r){
		int mid=(l+r)/2;
		vector <int> nw;
		auto op=mp.lower_bound(mid);
		for(auto i:(*op).second){
			if(s.find(i)!=s.end()) continue;
			add(i);
			if(press_buton()>mid) del(i);
			else nw.push_back(i);
		}
		mp[mid]=s;
		if((int)s.size()>=cad*mid){
			ans=mid;
			l=mid+1;
		}else{
			r=mid-1;
			for(auto i:nw) del(i);
		}
	}
	return ans;
}
/**  /\_/\
*   (= ._.)
*   / >💖 \>💕
**/

Compilation message

insects.cpp:107:9: warning: "/*" within comment [-Wcomment]
  107 | /**  /\_/\
      |          
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:93:7: error: 'press_buton' was not declared in this scope; did you mean 'press_button'?
   93 |    if(press_buton()>mid) del(i);
      |       ^~~~~~~~~~~
      |       press_button