Submission #150098

# Submission time Handle Problem Language Result Execution time Memory
150098 2019-09-01T07:42:45 Z お前はもう死んでいる(#3784, kuroni, nvmdava, tfg) Lokahian Relics (FXCUP4_lokahia) C++17
0 / 100
1000 ms 848 KB
#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 205;

random_device rd;
mt19937_64 mt(rd());

int n, dsu[N], con[N][N];
vector<int> ve[N];

int rand(int l, int r)
{
	uniform_int_distribution<int> uni(l, r);
	return uni(mt);
}

int trace(int u)
{
	return dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]);
}

void connect(int u, int v)
{
	if ((u = trace(u)) == (v = trace(v)))
		return;
	if (dsu[u] > dsu[v])
		swap(u, v);
	dsu[u] += dsu[v];
	dsu[v] = u;
	vector<int> tmp;
	for (int j = 1; j <= n; j++)
		if (con[u][j] == -1 || con[v][j] == -1)
			tmp.push_back(j);
	for (int &a : ve[u])
		for (int &b : ve[v])
			con[a][b] = con[b][a] = 1;
	for (int &b : ve[v])
		ve[u].push_back(b);
	ve[v].clear();
	for (int &a : ve[u])
		for (int &b : tmp)
			con[a][b] = con[b][a] = -1;
}

int FindBase(int _n)
{
	n = _n;
	for (int i = 0; i < n; i++)
	{
		dsu[i] = -1;
		ve[i] = {i};
		con[i][i] = 1;
	}
	for (int i = 1; i <= 300; i++)
	{
		int u, v;
		do
		{
			u = rand(0, n - 1);
			v = rand(0, n - 1);
		} while (con[u][v] != 0);
		u = trace(u); v = trace(v);
		int rt = CollectRelics(u, v);
		if (rt == -1)
		{
			for (int &a : ve[u])
				for (int &b : ve[v])
					con[a][b] = con[b][a] = -1;
		}
		else
		{
			connect(rt, u);
			connect(rt, v);
		}
	}
	for (int i = 0; i < n; i++)
		if (-dsu[i] >= n / 2)
			return i;
	return -1;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3099 ms 640 KB Time limit exceeded
2 Incorrect 7 ms 640 KB Wrong
3 Correct 6 ms 640 KB Correct : C = 300
4 Execution timed out 3096 ms 768 KB Time limit exceeded
5 Execution timed out 3099 ms 768 KB Time limit exceeded
6 Correct 10 ms 768 KB Correct : C = 300
7 Incorrect 9 ms 768 KB Wrong
8 Correct 6 ms 640 KB Correct : C = 300
9 Execution timed out 3097 ms 512 KB Time limit exceeded
10 Correct 11 ms 768 KB Correct : C = 300
11 Execution timed out 3097 ms 512 KB Time limit exceeded
12 Correct 7 ms 768 KB Correct : C = 300
13 Execution timed out 3099 ms 640 KB Time limit exceeded
14 Execution timed out 3099 ms 768 KB Time limit exceeded
15 Correct 9 ms 768 KB Correct : C = 300
16 Correct 6 ms 768 KB Correct : C = 300
17 Execution timed out 3099 ms 640 KB Time limit exceeded
18 Execution timed out 3099 ms 640 KB Time limit exceeded
19 Correct 7 ms 768 KB Correct : C = 300
20 Correct 10 ms 768 KB Correct : C = 300
21 Execution timed out 3099 ms 768 KB Time limit exceeded
22 Execution timed out 3099 ms 640 KB Time limit exceeded
23 Correct 6 ms 768 KB Correct : C = 300
24 Correct 8 ms 640 KB Correct : C = 300
25 Execution timed out 3096 ms 848 KB Time limit exceeded
26 Incorrect 8 ms 640 KB Wrong
27 Incorrect 10 ms 768 KB Wrong