Submission #1049841

# Submission time Handle Problem Language Result Execution time Memory
1049841 2024-08-09T05:42:41 Z 정희우(#11049) Chameleon's Love (JOI20_chameleon) C++17
100 / 100
30 ms 4440 KB
#include "chameleon.h"
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;

const int MAX_N=1010;

int n,n2;
vint edge[MAX_N];
int check[MAX_N];
vint group[2];
int match[MAX_N][MAX_N];

struct Obj
{
	int i,c;
	bool operator < (const Obj &o) const
	{
		return abs(c)>abs(o.c);
	}
};

int dfsc(int v)
{
	check[v]=1;
	int r=1;
	for(auto v0 : edge[v])
		if(!check[v0])
			r-=dfsc(v0);
	return r;
}

void dfsg(int v,int t)
{
	group[t].push_back(v);
	check[v]=2;
	for(auto v0 : edge[v])
		if(check[v0]==1)
			dfsg(v0,!t);
}

void make_group(int k)
{
	group[0].clear();
	group[1].clear();
	fill(check,check+n2+1,0);
	vector<Obj> cnts;
	for(int i=1;i<=k;i++)
		if(!check[i])
			cnts.push_back({i,dfsc(i)});
	sort(cnts.begin(),cnts.end());
	for(auto o : cnts)
		dfsg(o.i,(group[0].size()-group[1].size())*o.c>0);
}

int binarys(int v,const vint &askv)
{
	int lb=0,ub=askv.size()-1;
	vint ask;
	while(lb<ub)
	{
		int m=(lb+ub)>>1;
		ask={v};
		for(int i=lb;i<=m;i++)ask.push_back(askv[i]);
		if(Query(ask)==ask.size())lb=m+1;
		else ub=m;
	}
	return askv[lb];
}

void find_edge(int v,int t)
{
	if(edge[v].size()==3)return;
	vint ask;
	for(auto i : group[t])
	{
		int flag=1;
		for(int v0 : edge[v])
			if(i==v0)flag=0;
		if(flag)ask.push_back(i);
	}
	if(ask.empty())return;
	ask.push_back(v);
	if(Query(ask)==ask.size())return;
	ask.pop_back();
	int u=binarys(v,ask);
	edge[v].push_back(u);
	edge[u].push_back(v);
	find_edge(v,t);
}

void fill_match(int v)
{
	if(edge[v].size()!=3)return;
	int a[3]={edge[v][0],edge[v][1],edge[v][2]};
	vint ask={v,a[0],a[1]};
	int a1=Query(ask);
	ask={v,a[0],a[2]};
	int a2=Query(ask);
	int mark;
	if(a1==1)mark=a[2];
	else if(a2==1)mark=a[1];
	else mark=a[0];
	match[v][mark]=match[mark][v]=1;
}

void show_ans()
{
	fill(check,check+n2+1,0);
	for(int i=1;i<=n2;i++)
		if(!check[i])
			for(auto j : edge[i])
				if(!match[i][j])
				{
					Answer(i,j);
					check[i]=check[j]=1;
				}
}

void Solve(int N)
{
	n=N;
	n2=n*2;
	for(int i=2;i<=n2;i++)
	{
		make_group(i-1);
		for(int t=0;t<2;t++)
			find_edge(i,t);
	}
	for(int i=1;i<=n2;i++)
		fill_match(i);
	show_ans();
}

Compilation message

chameleon.cpp: In function 'int binarys(int, const vint&)':
chameleon.cpp:70:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   if(Query(ask)==ask.size())lb=m+1;
      |      ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'void find_edge(int, int)':
chameleon.cpp:89:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  if(Query(ask)==ask.size())return;
      |     ~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 19 ms 344 KB Output is correct
5 Correct 19 ms 344 KB Output is correct
6 Correct 19 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 19 ms 524 KB Output is correct
9 Correct 20 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 29 ms 4440 KB Output is correct
4 Correct 29 ms 4432 KB Output is correct
5 Correct 29 ms 4432 KB Output is correct
6 Correct 30 ms 4380 KB Output is correct
7 Correct 30 ms 4384 KB Output is correct
8 Correct 29 ms 4432 KB Output is correct
9 Correct 29 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 19 ms 344 KB Output is correct
5 Correct 19 ms 344 KB Output is correct
6 Correct 19 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 19 ms 524 KB Output is correct
9 Correct 20 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 29 ms 4440 KB Output is correct
31 Correct 29 ms 4432 KB Output is correct
32 Correct 29 ms 4432 KB Output is correct
33 Correct 30 ms 4380 KB Output is correct
34 Correct 30 ms 4384 KB Output is correct
35 Correct 29 ms 4432 KB Output is correct
36 Correct 29 ms 4432 KB Output is correct
37 Correct 28 ms 4432 KB Output is correct
38 Correct 19 ms 344 KB Output is correct
39 Correct 29 ms 4340 KB Output is correct
40 Correct 29 ms 4396 KB Output is correct
41 Correct 30 ms 4424 KB Output is correct
42 Correct 19 ms 516 KB Output is correct
43 Correct 30 ms 4428 KB Output is correct
44 Correct 29 ms 4432 KB Output is correct
45 Correct 30 ms 4432 KB Output is correct