# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
819062 | Faisal_Saqib | Carnival (CEOI14_carnival) | C++17 | 10 ms | 316 KiB |
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 <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
int par[1000];
int val[1000];
int get(int x)
{
if(par[x]==x)
{
return x;
}
return par[x]=get(par[x]);
}
void join(int a,int b)
{
a=get(a);
b=get(b);
if(a==b)
{
return;
}
if(val[a]<val[b])
{
par[b]=a;
}
else
{
par[a]=b;
}
}
bool match(vector<int> v,int y)
{
cout<<v.size()+1;
for(auto i:v)
{
cout<<' '<<i;
}
cout<<' '<<y<<endl;
cin>>y;
if(y==v.size())
{
return 1;
}
else{
return 0;
}
}
void solve(vector<int> H,int pe)
{
if(H.size()==1)
{
join(H[0],pe);
return;
}
vector<int> fh,sh;
int mid=(H.size()+1)/2;
for(int i=0;i<H.size();i++)
{
if(i<mid)
{
fh.push_back(H[i]);
}
else
{
sh.push_back(H[i]);
}
}
if(match(fh,pe))
{
solve(fh,pe);
}
else
{
solve(sh,pe);
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
par[i]=i;
val[i]=i;
}
vector<int> hg={1};
int cdx=2;
val[1]=1;
for(int i=2;i<=n;i++)
{
if(match(hg,i))
{
solve(hg,i);
}
else
{
hg.push_back(i);
val[i]=cdx++;
}
}
cout<<0;
for(int i=1;i<=n;i++)
{
cout<<' '<<val[get(i)];
}
cout<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |