# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64719 | bazsi700 | Carnival (CEOI14_carnival) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
#define ll long long
int col[151];
int query(vector<int> &v) {
cout << v.size() << " "
for(int el : v) {
cout << el << " ";
}
cout << "\n" << flush;
int x;
cin >> x;
return x;
}
bool hasmatch(vector<int> &v, int x) {
if(v.size() == 1) {
v.push_back(x);
int a1 = query(v);
v.pop_back();
return (a1 == 1);
}
int a1 = query(v);
v.push_back(i);
int a2 = query(x);
v.pop_back();
return (a1 == a2);
}
void solve(vector<int> &v, int x, int currcol) {
if(!hasmatch(v,x)) {
return;
}
if(v.size() == 1) {
col[v][0] = currcol;
return;
}
vector<int> v1 (v.size()/2);
vector<int> v2 (v.size()-v.size()/2);
for(int i = 0; i < v.size()/2; i++) {
v1[i] = v[i];
}
for(int i = 0; i < v.size()-v.size()/2; i++) {
v2[i] = v[i+v.size()/2];
}
solve(v1,x,currcol);
solve(v2,x,currcol);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int newcol = 1;
for(int i = 1; i <= n; i++) {
if(col[i] != 0) {
continue;
}
vector<int> v (n-i);
for(int j = i+1; j <= n; j++) {
v[j-i-1] = j;
}
col[i] = newcol;
solve(v,i,newcol++);
}
cout << "0 ";
for(int i = 1; i <= n; i++) {
cout << col[i] << " ";
}
return 0;
}