This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
map<vector<int>,int> store;
set<int> cur,machine;
void add(int&i)
{
cur.insert(i-1);
}
void rem(int&i)
{
cur.erase(i-1);
}
void khatam()
{
cur.clear();
}
int ask()
{
vector<int> vec(begin(cur),end(cur));
if(store.find(vec)!=store.end())return store[vec];
for(auto&i:cur)
if(machine.find(i)==machine.end())
move_inside(i);
for(auto&j:machine)
if(cur.find(j)==cur.end())
move_outside(j);
machine=cur;
store[vec]=press_button();
return store[vec];
}
int min_cardinality(int n)
{
vector<int> heads={1};
int one=1;
add(one);
for(int i=2;i<=n;i++)
{
add(i);
if(ask()==1)
heads.push_back(i);
else
rem(i);
}
int sz=heads.size(),np=n;
int sm=0;
while(1)
{
int mid=(np)/sz;
khatam();
for(int i=1;i<=n and sm<(sz*mid);i++)
{
if(i<=mid)
{
add(i);
sm++;
}
else
{
add(i);
if(ask()>mid)
{
rem(i);
}
else
{
sm++;
}
}
}
if(sm==((sz*mid)))
{
return mid; // this is the answer
}
else{
np=sm;
}
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |