답안 #127604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127604 2019-07-09T16:14:37 Z TadijaSebez CEOI16_icc (CEOI16_icc) C++11
100 / 100
168 ms 636 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=105;
int A[N],B[N];
int Ask(vector<int> a, vector<int> b)
{
	for(int i=0;i<a.size();i++) A[i]=a[i];
	for(int i=0;i<b.size();i++) B[i]=b[i];
	return query(a.size(),b.size(),A,B);
}
int p[N],n;
int Find(int x){ return p[x]==x?x:p[x]=Find(p[x]);}
void Union(int x, int y){ p[Find(x)]=Find(y);}
void init(){ for(int i=0;i<N;i++) p[i]=i;}
bool use[N];
vector<int> Extend(vector<int> a)
{
	vector<int> _a;
	for(int i=1;i<=n;i++) use[i]=0;
	for(int i:a) use[i]=1;
	for(int i=1;i<=n;i++) if(use[Find(i)]) _a.pb(i);
	return _a;
}
int AskAll(vector<int> a, vector<int> b)
{
	return Ask(Extend(a),Extend(b));
}
vector<int> Reduce1(vector<int> x, vector<int> y)
{
	while(x.size()>1)
	{
		vector<int> v[2];
		for(int i=0;i<x.size();i++) v[i&1].pb(x[i]);
		if(AskAll(v[0],y)) x=v[0];
		else x=v[1];
	}
	return x;
}
vector<int> Reduce2(vector<int> x, vector<int> y)
{
	while(x.size()>1)
	{
		vector<int> v[2];
		for(int i=0;i<x.size();i++) v[i&1].pb(x[i]);
		if(Ask(v[0],y)) x=v[0];
		else x=v[1];
	}
	return x;
}
void run(int _n)
{
	n=_n;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	init();
	for(int t=1;t<n;t++)
	{
		vector<int> root,v[2],u[2];
		for(int i=1;i<=n;i++) if(Find(i)==i) root.pb(i);
		shuffle(root.begin(),root.end(),rng);
		for(int l=0;;l++)
		{
			for(int i=0;i<root.size();i++) use[root[i]]=(i>>l)&1;
			v[0].clear();
			v[1].clear();
			for(int i=1;i<=n;i++) v[use[Find(i)]].pb(i);
			if(Ask(v[0],v[1])) break;
		}
		//for(int i=1;i<=n;i++) if(Find(i)==i) u[use[i]].pb(i);
		//u[0]=Reduce1(u[0],u[1]);
		//u[1]=Reduce1(u[1],u[0]);
		//v[0]=Extend(u[0]);
		//v[1]=Extend(u[1]);
		v[0]=Reduce2(v[0],v[1]);
		v[1]=Reduce2(v[1],v[0]);
		setRoad(v[0][0],v[1][0]);
		Union(v[0][0],v[1][0]);
	}
}

Compilation message

icc.cpp: In function 'int Ask(std::vector<int>, std::vector<int>)':
icc.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a.size();i++) A[i]=a[i];
              ~^~~~~~~~~
icc.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<b.size();i++) B[i]=b[i];
              ~^~~~~~~~~
icc.cpp: In function 'std::vector<int> Reduce1(std::vector<int>, std::vector<int>)':
icc.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<x.size();i++) v[i&1].pb(x[i]);
               ~^~~~~~~~~
icc.cpp: In function 'std::vector<int> Reduce2(std::vector<int>, std::vector<int>)':
icc.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<x.size();i++) v[i&1].pb(x[i]);
               ~^~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:64:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<root.size();i++) use[root[i]]=(i>>l)&1;
                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Ok! 98 queries used.
2 Correct 8 ms 504 KB Ok! 97 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 504 KB Ok! 524 queries used.
2 Correct 50 ms 604 KB Ok! 642 queries used.
3 Correct 50 ms 504 KB Ok! 634 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 576 KB Ok! 1392 queries used.
2 Correct 168 ms 568 KB Ok! 1603 queries used.
3 Correct 151 ms 504 KB Ok! 1520 queries used.
4 Correct 151 ms 508 KB Ok! 1505 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 632 KB Ok! 1491 queries used.
2 Correct 152 ms 504 KB Ok! 1506 queries used.
3 Correct 159 ms 504 KB Ok! 1577 queries used.
4 Correct 143 ms 504 KB Ok! 1449 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 504 KB Ok! 1573 queries used.
2 Correct 160 ms 636 KB Ok! 1569 queries used.
3 Correct 162 ms 572 KB Ok! 1585 queries used.
4 Correct 160 ms 504 KB Ok! 1591 queries used.
5 Correct 153 ms 560 KB Ok! 1469 queries used.
6 Correct 154 ms 636 KB Ok! 1533 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 600 KB Ok! 1588 queries used.
2 Correct 164 ms 504 KB Ok! 1580 queries used.