답안 #819062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819062 2023-08-10T07:49:45 Z Faisal_Saqib 사육제 (CEOI14_carnival) C++17
100 / 100
10 ms 316 KB
#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

carnival.cpp: In function 'bool match(std::vector<int>, int)':
carnival.cpp:42:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  if(y==v.size())
      |     ~^~~~~~~~~~
carnival.cpp: In function 'void solve(std::vector<int>, int)':
carnival.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i=0;i<H.size();i++)
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 6 ms 312 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 4 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
6 Correct 5 ms 228 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 8 ms 256 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 3 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 3 ms 304 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 10 ms 304 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 3 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 6 ms 304 KB Output is correct
4 Correct 6 ms 308 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 2 ms 316 KB Output is correct