Submission #55463

# Submission time Handle Problem Language Result Execution time Memory
55463 2018-07-07T15:25:17 Z mraron ICC (CEOI16_icc) C++14
0 / 100
3 ms 692 KB
//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium
#include "icc.h"
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define FORN(i, n) for(int i=0;i<(n);i++)
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

int par[101], sz[101];

void init() {
	memset(par, -1, sizeof par);
	for(auto&i:sz) i=1;
}

int get(int x) {
	if(par[x]==-1) return x;
	return par[x]=get(par[x]);
}

void merge(int x, int y) {
	int px=get(x), py=get(y);
	if(sz[px]>sz[py]) swap(px, py);
	par[py]=px;
	sz[py]+=sz[px];
}


vector<int> convert(vector<int> d) {
	vector<int> ans;
	for(auto i:d) {
		for(int j=0;j<=100;++j) {
			if(get(j)==i) ans.pb(j);
		}
	}
	return ans;
}

bool ask(vector<int> a, vector<int> b, bool c=true) {
	if(c) {
		a=convert(a);
		b=convert(b);
	}
	
	int A[sz(a)];
	int B[sz(b)];
	for(int i=0;i<sz(a);++i) A[i]=a[i];
	for(int i=0;i<sz(b);++i) B[i]=b[i];
	
	return query(sz(a), sz(b), A, B);
}

pair<int,int> bisect(vector<int> a, vector<int> b) {
	if(sz(a)==1 && sz(b)==1) return {a[0], b[0]};
	
	if(sz(a)>sz(b)) swap(a,b);
	
	vector<int> a1,a2;
	vector<int> b1,b2;
	
	for(int i=0;i<sz(a)/2;++i) a1.pb(a[i]);
	for(int i=sz(a)/2;i<sz(a);++i) a2.pb(a[i]);
	
	for(int i=0;i<sz(b)/2;++i) b1.pb(b[i]);
	for(int i=sz(b)/2;i<sz(b);++i) b2.pb(b[i]);
	
	
	if(sz(a)==1) {
		if(ask(a, b1, false)) return bisect(a,b1);
		else return bisect(a, b2);
	}
	
	if(ask(a1,b1,false)) return bisect(a1, b1);
	else if(ask(a1,b2,false)) return bisect(a1,b2);
	else if(ask(a2,b1,false)) return bisect(a2, b1);
	else return bisect(a2,b2);
	
	return {-1,-1};
}

void run(int n) {
	init();
	
	int cnt=0;
	while(cnt<n-1) {
		set<int> groups;
		for(int i=1;i<=n;++i) groups.insert(get(i));
		vector<int> gs;
		for(int i:groups) gs.pb(i);
		
		pair<int,int> el;
		for(int i=0;i<=log2(sz(gs));++i) {
			vector<int> ga,gb;
			for(int j=0;j<sz(gs);++j) {
				if(j&(1<<i)) ga.pb(j);
				else gb.pb(j);
			}
			
			if(ask(ga, gb)) {
				el=bisect(convert(ga), convert(gb));
				break ;
			}
		}
		
		setRoad(el.xx, el.yy);
		
		merge(el.xx, el.yy);
		
		cnt++;
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 588 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 636 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 692 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -