답안 #56285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56285 2018-07-11T02:01:43 Z Yehezkiel CEOI16_icc (CEOI16_icc) C++11
90 / 100
228 ms 816 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
const int MAXN=100;
int par[MAXN+5],n;
int finds(int x){
	if(par[x]!=x)
		par[x]=finds(par[x]);
	return par[x];
}
bool connected(int u,int v){
	return (finds(u)==finds(v));
}
void gabung(int u,int v){
	u=finds(u),v=finds(v);
	if(u==v)
		return;
	par[v]=u;
}
int tanya(vector <int> a,vector <int> b){				//O(N)
	int arr1[105];int arr2[105];
	for(int i=0;i<a.size();i++)
		arr1[i]=a[i];
	for(int i=0;i<b.size();i++)
		arr2[i]=b[i];
	
	return query(a.size(),b.size(),arr1,arr2);
}
void print(vector <int> arr){
	cout<<"printing arr"<<endl;
	for(int i=0;i<arr.size();i++)
		cout<<arr[i]<<" ";
	cout<<endl;
}
void expand(vector <int> &vec){		//isinya cuman kepala suku	O(N)
	bool root[MAXN+5];
	for(int i=1;i<=n;i++)
		root[i]=false;
	for(auto isi:vec)
		root[isi]=true;
	vec.clear();
	for(int i=1;i<=n;i++)
		if(root[finds(i)])
			vec.pb(i);
}
void perkecil(vector <int> &now,const vector <int> &other){			//O(NlogN)
	vector <int> temp;
	while(now.size()>1)				//O(logN)
	{
		temp.clear();
		for(int i=now.size()/2;i<now.size();i++)
			temp.pb(now[i]);
		now.resize(now.size()/2);
		
		if(tanya(now,other)==0)				//O(N)
			now=temp;
	}
}

void bagiDua(vector <int> &vec,int &lebih,vector<vector<int> > &tampung){
	random_shuffle(all(vec));
	int ambil=vec.size()/2;
	if(lebih&&(vec.size()&1))
		lebih--,ambil++;
	
	vector <int> kiri,kanan;
	for(int i=0;i<vec.size();i++)
	{
		if(i<ambil)
			kiri.pb(vec[i]);
		else
			kanan.pb(vec[i]);
	}
	tampung.pb(kiri);tampung.pb(kanan);
}
vector <int> kiri,kanan;
void findAnggota(){
	vector <vector <int> > anggota,baru;
	anggota.resize(1);
	for(int i=1;i<=n;i++)
	{
		if(par[i]==i)
			anggota[0].pb(i);
	}
	
	//cout<<"MULAI"<<endl;
	for(int loop=0;;loop++)
	{
		baru.clear();
		int lebih=0;
		for(auto &isi:anggota)
			lebih+=isi.size()%2;
		lebih/=2;
		
		int terbesar=-1;
		for(auto &isi:anggota)
		{
			terbesar=max(terbesar,(int) isi.size());
			bagiDua(isi,lebih,baru);
		}
		assert(terbesar>1);
		
		kiri.clear();kanan.clear();
		for(int i=0;i<baru.size();i++)
		{
			for(auto isi:baru[i])
			{
				if(i&1)
					kanan.pb(isi);
				else
					kiri.pb(isi);
			}
		}
		assert(lebih==0);
		//cout<<loop<<" "<<target<<" "<<(ukuran<<loop)<<" "<<lebih<<endl;
		//cout<<kiri.size()<<" "<<kanan.size()<<endl;
		assert(abs((int) kiri.size() - (int) kanan.size())<=1);
		expand(kiri),expand(kanan);
		if(tanya(kiri,kanan))
			break;
		
		anggota=baru;
	}
}
void run(int _n){
	srand(2006);
	n=_n;
	for(int i=1;i<=n;i++)
		par[i]=i;
	
	for(int i=0;i<n-1;i++)
	{
		findAnggota();
		perkecil(kiri,kanan);
		perkecil(kanan,kiri);
		setRoad(kiri[0],kanan[0]);
		gabung(kiri[0],kanan[0]);
	}
}

Compilation message

icc.cpp: In function 'int tanya(std::vector<int>, std::vector<int>)':
icc.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a.size();i++)
              ~^~~~~~~~~
icc.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<b.size();i++)
              ~^~~~~~~~~
icc.cpp: In function 'void print(std::vector<int>)':
icc.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<arr.size();i++)
              ~^~~~~~~~~~~
icc.cpp: In function 'void perkecil(std::vector<int>&, const std::vector<int>&)':
icc.cpp:54:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=now.size()/2;i<now.size();i++)
                          ~^~~~~~~~~~~
icc.cpp: In function 'void bagiDua(std::vector<int>&, int&, std::vector<std::vector<int> >&)':
icc.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vec.size();i++)
              ~^~~~~~~~~~~
icc.cpp: In function 'void findAnggota()':
icc.cpp:107:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<baru.size();i++)
               ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 504 KB Ok! 98 queries used.
2 Correct 13 ms 664 KB Ok! 102 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 664 KB Ok! 530 queries used.
2 Correct 84 ms 664 KB Ok! 679 queries used.
3 Correct 71 ms 664 KB Ok! 679 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 664 KB Ok! 1455 queries used.
2 Correct 219 ms 684 KB Ok! 1700 queries used.
3 Correct 222 ms 748 KB Ok! 1594 queries used.
4 Correct 180 ms 748 KB Ok! 1544 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 748 KB Ok! 1566 queries used.
2 Correct 163 ms 748 KB Ok! 1568 queries used.
3 Correct 185 ms 768 KB Ok! 1626 queries used.
4 Correct 168 ms 768 KB Ok! 1489 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 768 KB Ok! 1647 queries used.
2 Correct 222 ms 768 KB Ok! 1640 queries used.
3 Correct 186 ms 768 KB Ok! 1643 queries used.
4 Correct 180 ms 768 KB Ok! 1628 queries used.
5 Correct 183 ms 816 KB Ok! 1509 queries used.
6 Correct 228 ms 816 KB Ok! 1563 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 816 KB Too many queries! 1629 out of 1625
2 Halted 0 ms 0 KB -