Submission #55470

# Submission time Handle Problem Language Result Execution time Memory
55470 2018-07-07T15:47:10 Z mraron ICC (CEOI16_icc) C++14
90 / 100
220 ms 896 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);
	par[px]=py;
	sz[py]+=sz[px];
}

int n_;
vector<int> convert(vector<int> d) {
	vector<int> ans;
	for(auto i:d) {
		for(int j=1;j<=n_;++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(ask(a,b1,false)) return bisect(a, b1);
	else return bisect(a, b2);
	
	return {-1,-1};
}

void run(int n) {
	init();
	n_=n;
	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(gs[j]);
				else gb.pb(gs[j]);
			}
			
			if(ask(ga, gb)) {
		//		cerr<<"ok\n";
				el=bisect(convert(ga), convert(gb));
				break ;
			}
		}
		
	//	cerr<<el.xx<<" "<<el.yy<<"\n"; 
		
		setRoad(el.xx, el.yy);
		
		merge(el.xx, el.yy);
		
		cnt++;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 504 KB Ok! 95 queries used.
2 Correct 9 ms 504 KB Ok! 102 queries used.
# Verdict Execution time Memory Grader output
1 Correct 44 ms 648 KB Ok! 555 queries used.
2 Correct 64 ms 648 KB Ok! 676 queries used.
3 Correct 69 ms 768 KB Ok! 678 queries used.
# Verdict Execution time Memory Grader output
1 Correct 173 ms 768 KB Ok! 1444 queries used.
2 Correct 207 ms 768 KB Ok! 1637 queries used.
3 Correct 172 ms 824 KB Ok! 1576 queries used.
4 Correct 162 ms 824 KB Ok! 1537 queries used.
# Verdict Execution time Memory Grader output
1 Correct 173 ms 824 KB Ok! 1510 queries used.
2 Correct 166 ms 824 KB Ok! 1481 queries used.
3 Correct 185 ms 824 KB Ok! 1680 queries used.
4 Correct 174 ms 824 KB Ok! 1472 queries used.
# Verdict Execution time Memory Grader output
1 Correct 174 ms 844 KB Ok! 1653 queries used.
2 Correct 190 ms 844 KB Ok! 1670 queries used.
3 Correct 180 ms 844 KB Ok! 1674 queries used.
4 Correct 180 ms 876 KB Ok! 1623 queries used.
5 Correct 220 ms 880 KB Ok! 1474 queries used.
6 Correct 183 ms 880 KB Ok! 1568 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 896 KB Too many queries! 1668 out of 1625
2 Halted 0 ms 0 KB -