Submission #131824

# Submission time Handle Problem Language Result Execution time Memory
131824 2019-07-17T17:37:09 Z bogdan10bos Carnival (CEOI14_carnival) C++14
20 / 100
65 ms 1000 KB
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 155;

int N, rem;
int f[NMAX];

map< vector<int>, int > mp;

int ask(vector<int> v)
{
	sort(begin(v), end(v));
	if(mp.count(v))	return mp[v];

	printf("%d ", int(v.size()));
	for(auto x: v)	printf("%d ", x);
	printf("\n");
	fflush(stdout);

	int ans;
	scanf("%d", &ans);
	mp[v] = ans;
	return ans;
}

int F(int x)
{
	if(f[x] == x)	return x;
	return f[x] = F(f[x]);
}

void finish()
{
	vector<int> sol;
	sol.resize(N + 2);
	int K = 0;
	for(int i = 1; i <= N; i++)
		if(sol[i] == 0)
		{
			K++;
			for(int j = i; j <= N; j++)
				if(F(i) == F(j))
					sol[j] = K;
		}

	printf("0 ");
	for(int i = 1; i <= N; i++)
		printf("%d ", sol[i]);
	printf("\n");
	fflush(stdout);
	exit(0);
}

void unite(int x, int y)
{
	int fx = F(x), fy = F(y);
	if(fx == fy)	return;
	f[fy] = fx;
	rem--;
	if(rem == 0)	finish();
}

vector<int> reduce(vector<int> v)
{
	vector<int> a;
	for(int i = 0; i < (int)v.size(); i++)
	{
		int x = v[i];
		bool ok = true;
		for(auto y: a)
			if(F(x) == F(y))
			{
				ok = false;
				break;
			}
		if(ok)	a.push_back(x);
	}
	return a;
}

void solve(vector<int> v)
{
	if(v.size() <= 1)	return;
	int cnt = ask(v);
	if(cnt == (int)v.size())	return;
	if(cnt == 1)
		for(auto x: v)	unite(x, v[0]);

	if(rem == 0)	return;

	v = reduce(v);

	if((int)v.size() <= 2)
	{
		solve(v);
		return;
	}

	int msk = 0;
	for(int b = 0; (1 << b) < (int)v.size(); b++)
	{
		msk |= (1 << b);
		vector<int> vec[2];
		for(int i = 0; i < (int)v.size(); i++)
			vec[ (i >> b) & 1 ].push_back(v[i]);

		solve(vec[0]);
		solve(vec[1]);
	}

	vector<int> vec[2];
	int k = 0;
	for(int i = 0; i < v.size(); i++)
		for(int j = i + 1; j < v.size(); j++)
			if( (i & j) == 0 && ( (i ^ msk) & (j ^ msk) ) == 0 )
			{
				vec[k].push_back(v[i]);
				vec[k].push_back(v[j]);
				k ^= 1;
			}

	solve(vec[0]);
	solve(vec[1]);
}

int main()
{
	scanf("%d", &N);
	vector<int> v;
	for(int i = 1; i <= N; i++)	f[i] = i, v.push_back(i);

	mt19937 g(chrono::high_resolution_clock::now().time_since_epoch().count());
	shuffle(v.begin(), v.end(), g);
	rem = N - ask(v);
	solve(v);
	finish();
	return 0;
}

Compilation message

carnival.cpp: In function 'void solve(std::vector<int>)':
carnival.cpp:115:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
carnival.cpp:116:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = i + 1; j < v.size(); j++)
                      ~~^~~~~~~~~~
carnival.cpp: In function 'int ask(std::vector<int>)':
carnival.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &ans);
  ~~~~~^~~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:130:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 504 KB Output is correct
2 Partially correct 51 ms 764 KB Partially correct
3 Correct 40 ms 760 KB Output is correct
4 Correct 9 ms 448 KB Output is correct
5 Correct 10 ms 376 KB Output is correct
6 Correct 2 ms 320 KB Output is correct
7 Partially correct 51 ms 704 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 456 KB Output is correct
2 Partially correct 53 ms 888 KB Partially correct
3 Correct 26 ms 504 KB Output is correct
4 Correct 12 ms 532 KB Output is correct
5 Correct 16 ms 412 KB Output is correct
6 Correct 9 ms 380 KB Output is correct
7 Correct 31 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 31 ms 492 KB Output is correct
3 Partially correct 65 ms 1000 KB Partially correct
4 Correct 10 ms 376 KB Output is correct
5 Correct 12 ms 448 KB Output is correct
6 Correct 18 ms 388 KB Output is correct
7 Partially correct 31 ms 704 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 464 KB Output is correct
2 Correct 27 ms 480 KB Output is correct
3 Correct 33 ms 532 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 15 ms 452 KB Output is correct
6 Correct 27 ms 508 KB Output is correct
7 Partially correct 55 ms 760 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 424 KB Output is correct
2 Correct 40 ms 772 KB Output is correct
3 Partially correct 46 ms 836 KB Partially correct
4 Correct 45 ms 760 KB Output is correct
5 Correct 19 ms 576 KB Output is correct
6 Correct 14 ms 504 KB Output is correct
7 Correct 9 ms 324 KB Output is correct