답안 #24670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24670 2017-06-10T21:00:54 Z bill_kondo CEOI16_icc (CEOI16_icc) C++14
18 / 100
236 ms 2100 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;

#define debug(args...) fprintf (stderr, args)

typedef pair <int, int> pii;
 
const int maxn = 1e2 + 10;
const int maxC = 1e2 + 10;
 
int n;
set <pii> e;
 
int c[maxn];
int d[maxn];

// int query (int szA, int szB, int a[], int b[])
// {
// 	debug ("query\n");
// 	debug ("%d\n", szA);
// 	for (int i = 0; i < szA; ++i)
// 		debug ("%d ", a[i]);

// 	debug ("\n");

// 	debug ("%d\n", szB);
// 	for (int i = 0; i < szB; ++i)
// 		debug ("%d ", b[i]);
// 	debug ("\n");

// 	int resp;

// 	scanf ("%d",&resp);

// 	return resp;
// }

// int setRoad (int a, int b)
// {
// 	debug ("road %d %d\n", a, b);
// }
 
void acha ()
{
	for (int a = 1; a <= n; ++a)
		for (int b = a + 1; b <= n; ++b)
			if (e.find (pii (a, b)) == e.end())
			{
				c[0] = {a};
				d[0] = {b};
 
				if (query (1, 1, c, d))
				{
					e.insert (pii (a, b));
					setRoad (a, b);
					return;
				}
			}
}
 
int pointer;
vector <int> adj[maxn];
bool mrk[maxn];
 
int node, E[maxn], p;
 
void combina (int l, int r)
{
	if (l == r)
	{
		node = d[l];
		return;
	}
 
	int mid = (l + r) >> 1;
 
	p = 0;
 
	for (int i = l; i <= mid; ++i)
		E[p++] = d[i];
 
	if (query (1, p, c, E))
		combina (l, mid);
	else
		combina (mid + 1, r);
}
 
void dfs (int v)
{
	mrk[v] = true;
 
	for (auto u: adj[v])
		if (!mrk[u])
			dfs (u);
}
 
void aresta ()
{	
	for (int v = 1; v <= n; ++v)
	{
		c[0] = v;
	
		for (int u = 1; u <= n; ++u)
			mrk[u] = false;
 
		dfs (v);
 
		pointer = 0;
		for (int u = 1; u <= n; ++u)
			if (!mrk[u])
				d[pointer++] = u;
 
		if (query (1, pointer, c, d))
		{
			combina (0, pointer - 1);
			adj[v].push_back (node);
			adj[node].push_back (v);
			setRoad (v, node);
			return;
		}
	}
}

vector <int> C[maxC];

void DFS (int v, int id)
{
	mrk[v] = true;
	C[id].push_back (v);

	for (auto u: adj[v])
		if (!mrk[u])
			DFS (u, id);
}

int pA, A[maxn];
int pB, B[maxn];
int pV, V[maxn];

int I, J;

void combineA (int l, int r)
{
	if (l == r)
	{
		I = l;
		return;
	}

	int mid = (l + r) >> 1;

	pV = 0;
	for (int i = l; i <= mid; ++i)
		V[pV++] = B[i];

	if (query (pA, pV, A, V))
		combineA (l, mid);
	else
		combineA (mid + 1, r);
}

void combineB (int l, int r)
{
	if (l == r)
	{
		J = l;
		return;
	}

	int mid = (l + r) >> 1;

	pV = 0;
	for (int i = l; i <= mid; ++i)
		V[pV++] = A[i];

	if (query (pB, pV, B, V))
		combineB (l, mid);
	else
		combineB (mid + 1, r);
}
 
void solve ()
{
	vector <int> ids;

	for (int v = 1; v <= n; ++v)
	{
		C[v].clear();
		mrk[v] = false;
	}

	int id = 0;
	for (int v = 1; v <= n; ++v)
		if (!mrk[v])
		{
			++id;
			DFS (v, id);
			ids.push_back (id);
		}

	int mid = id / 2;

	while (true)
	{
		srand(time(NULL));
		random_shuffle (ids.begin(), ids.end());

		pA = 0;
		for (int i = 0; i < mid; ++i)
			for (auto u: C[ids[i]])
				A[pA++] = u;

		pB = 0;
		for (int i = mid; i < id; ++i)
			for (auto u: C[ids[i]])
				B[pB++] = u;

		debug ("A:\n");
		for (int i = 0; i < pA; ++i)
			debug ("%d ", A[i]);
		debug ("\n");

		debug ("B:\n");
		for (int i = 0; i < pB; ++i)
			debug ("%d ", B[i]);
		debug ("\n");

		if (!query (pA, pB, A, B))
			continue;

		combineA (0, pB - 1);

		debug ("u = %d\n", B[I]);

		combineB (0, pA - 1);
		debug ("v = %d\n", A[J]);

		setRoad (A[J], B[I]);

		adj[B[I]].push_back (A[J]);
		adj[A[J]].push_back (B[I]);

		break;
	}
}
 
void run (int N)
{
	n = N;
 
	for (int i = 1; i <= n - 1; ++i)
	{
		if (N == 15) acha ();
		else if (N == 50) aresta ();
		else if (N == 100) solve ();
	}
}

// int main ()
// {
// 	run (5);
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 2096 KB Ok! 1015 queries used.
2 Correct 56 ms 2092 KB Ok! 1010 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 2092 KB Ok! 1508 queries used.
2 Correct 96 ms 2096 KB Ok! 1483 queries used.
3 Correct 123 ms 2100 KB Ok! 1517 queries used.
# 결과 실행 시간 메모리 Grader output
1 Runtime error 236 ms 2092 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 223 ms 2096 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 216 ms 2096 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 229 ms 2092 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -