#include "bits/stdc++.h"
#include "insects.h"
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
vector<int> mach;
void clear_mach(){
while(!mach.empty()){
move_outside(mach.back());
mach.pop_back();
}
}
int solve_paralel(vector<int> cand){
if(sz(cand)==1) return 1;
mach.push_back(0);
move_inside(0);
vector<int> tk,hm;
tk.push_back(0);
for(int i=1;i<sz(cand);i++){
move_inside(i);
mach.push_back(i);
if(press_button()==1) tk.push_back(i);
else{
hm.push_back(i);
move_outside(i);
mach.pop_back();
}
}
int n=sz(tk),m=sz(hm);
if(n==1) return sz(cand);
if(m<n) return 1;
int L[m],R[m];
for(int i=0;i<m;i++){
L[i]=0;
R[i]=n-1;
}
for(int j=0;j<=__lg(n);j++){
clear_mach();
vector<int> dene[n];
for(int i=0;i<m;i++) if(L[i]!=R[i]) dene[(L[i]+R[i])/2].push_back(i);
for(int i=0;i<n;i++){
move_inside(tk[i]);
mach.push_back(tk[i]);
for(int x:dene[i]){
move_inside(hm[x]);
mach.push_back(hm[x]);
if(press_button()==2) R[x]=i;
else L[x]=i+1;
move_outside(hm[x]);
mach.pop_back();
}
}
}
int ans=sz(cand);
vector<int> mark(n,1);
for(int i=0;i<m;i++) mark[L[i]]++;
for(int i=0;i<n;i++) ans=min(ans,mark[i]);
return ans;
}
int check_ans(vector<int> cand,int l,int r){
int K = l+sqrtl(r-l);
clear_mach();
mach.push_back(0);
move_inside(0);
vector<int> takla;
for(int i=1;i<sz(cand);i++){
mach.push_back(i);
move_inside(i);
if(press_button()>=K){
takla.push_back(i);
move_outside(i);
mach.pop_back();
}
}
clear_mach();
for(int x:takla){
move_inside(x);
mach.push_back(x);
if(press_button()==2){
move_outside(x);
mach.pop_back();
}
}
vector<int> buyuk,kucuk;
for(int x:takla) buyuk.push_back(x);
clear_mach();
for(int x:cand){
move_inside(x);
mach.push_back(x);
if(press_button()==2) buyuk.push_back(x);
else kucuk.push_back(x);
move_outside(x);
mach.pop_back();
}
if(kucuk.empty()) return solve_paralel(cand);
else return check_ans(cand,l,K-1);
}
int min_cardinality(int n){
vector<int> res;
for(int i=0;i<n;i++) res.push_back(i);
return check_ans(res,1,n);
}
/*void _(){
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
188 ms |
3356 KB |
Too many queries. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
188 ms |
3356 KB |
Too many queries. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
197 ms |
1232 KB |
Too many queries. |
2 |
Halted |
0 ms |
0 KB |
- |