#include <bits/stdc++.h>
using namespace std;
int tip[151];
int gazda[151];
int n;
int prasaj(int l,int r)
{
cout<<r-l+1<<" ";
for (int i=l;i<=r;i++) cout<<i<<" ";
cout<<endl;
int x;
cin>>x;
return x;
}
void najdi(int l,int r)
{
vector<int> grupa1,grupa2;
int mid = (l+r)/2;
bool vnatre[151];
memset(vnatre,0,sizeof(vnatre));
for (int i=l;i<=mid;i++)
{
int x = tip[i];
if (vnatre[x]==false)
{
vnatre[x]=true;
grupa1.push_back(i);
}
}
for (int i=mid+1;i<=r;i++)
{
int x = tip[i];
if (vnatre[x]==false)
{
vnatre[x]=true;
grupa2.push_back(i);
}
}
bool visited[151];
memset(visited,0,sizeof(visited));
for (int i=0;i<grupa1.size();i++)
{
for (int j=0;j<grupa2.size();j++)
{
int a=grupa1[i],b=grupa2[j];
if (visited[a] || visited[b]) continue;
cout<<"2 "<<a<<" "<<b<<endl;
int x;
cin>>x;
if (x==1)
{
visited[a]=true;
visited[b]=true;
for (int q=l;q<=r;q++)
{
if (tip[q]==tip[b]) tip[q]=tip[a];
}
}
}
}
}
int bs(int l,int r)
{
if (l==r) return 1;
int mid = (l+r)/2;
int x = bs(l,mid) + bs(mid+1,r);
int y = prasaj(l,r);
if (x!=y) najdi(l,r);
return y;
}
int stepen()
{
int x=1;
while(x<n) x*=2;
return x;
}
int main()
{
cin>>n;
for (int i=1;i<=n;i++) tip[i]=i;
bs(1,n);
map<int,int> pr;
int p = 1;
for (int i=1;i<=n;i++)
{
int x = tip[i];
if (pr[x]==0)
{
pr[x]=p;
p++;
}
}
cout<<0<<" ";
for (int i=1;i<=n;i++) cout<<pr[tip[i]]<<" ";
cout<<endl;
return 0;
}
Compilation message
carnival.cpp: In function 'void najdi(int, int)':
carnival.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i=0;i<grupa1.size();i++)
| ~^~~~~~~~~~~~~~
carnival.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j=0;j<grupa2.size();j++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Integer 12 violates the range [1, 11] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
600 KB |
Integer 6 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Integer 2 violates the range [1, 1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Integer 5 violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Integer 3 violates the range [1, 2] |
2 |
Halted |
0 ms |
0 KB |
- |