Submission #61430

# Submission time Handle Problem Language Result Execution time Memory
61430 2018-07-26T00:18:16 Z qkxwsm Collapse (JOI18_collapse) C++17
5 / 100
15000 ms 29600 KB
#include "collapse.h"
#include <bits/stdc++.h>

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 100000

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

int N, K, Q;
bool eid[MAXN];
pii ed[MAXN];
pii quer[MAXN];
vector<pii> queries[MAXN];
int ans[MAXN];
set<int> edge[MAXN];
int dsu[MAXN];

int find_parent(int u)
{
	if (u == dsu[u])
	{
		return u;
	}
	dsu[u] = find_parent(dsu[u]);
	return dsu[u];
}
void merge(int u, int v)
{
	u = find_parent(u);
	v = find_parent(v);
	if (u == v)
	{
		return;
	}
	dsu[u] = v;
	return;
}
int slit(int x)
{
	for (int i = 0; i < N; i++)
	{
		dsu[i] = i;
	}
	for (int u = 0; u < N; u++)
	{
		for (int v : edge[u])
		{
			if (v > u)
			{
				break;
			}
			if (u > x && v <= x)
			{
				continue;
			}
			merge(u, v);
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++)
	{
		if (find_parent(i) == i) res++;
	}
	return res;
}
vi simulateCollapse(int n, vi t, vi x, vi y, vi w, vi p)
{
	N = n;
	K = t.size();
	Q = w.size();
	for (int i = 0; i < K; i++)
	{
		eid[i] = t[i];
		ed[i] = MP(x[i], y[i]);
	}
	for (int i = 0; i < Q; i++)
	{
		quer[i] = MP(w[i], p[i]); //collapse at p
		queries[w[i]].PB(MP(p[i], i));
	}
//	cerr << "huh\n";
	for (int i = 0; i < K; i++)
	{
		int u = ed[i].fi, v = ed[i].se;
		if (eid[i])
		{
			edge[u].erase(v);
			edge[v].erase(u);
		}
		else
		{
			edge[u].insert(v);
			edge[v].insert(u);
		}
		for (pii x : queries[i])
		{
			ans[x.se] = slit(x.fi);
		}
	}
	vi res(Q);
	for (int i = 0; i < Q; i++)
	{
		res[i] = ans[i];
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 7928 KB Output is correct
2 Correct 11 ms 7928 KB Output is correct
3 Correct 12 ms 7928 KB Output is correct
4 Correct 14 ms 7928 KB Output is correct
5 Correct 18 ms 8300 KB Output is correct
6 Correct 341 ms 8668 KB Output is correct
7 Correct 88 ms 8668 KB Output is correct
8 Correct 80 ms 8668 KB Output is correct
9 Correct 97 ms 8668 KB Output is correct
10 Correct 242 ms 8704 KB Output is correct
11 Correct 853 ms 9264 KB Output is correct
12 Correct 785 ms 9320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12648 KB Output is correct
2 Correct 46 ms 13436 KB Output is correct
3 Correct 146 ms 20128 KB Output is correct
4 Correct 86 ms 20128 KB Output is correct
5 Correct 345 ms 22248 KB Output is correct
6 Correct 6761 ms 22248 KB Output is correct
7 Execution timed out 15088 ms 27196 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 27196 KB Output is correct
2 Correct 53 ms 27196 KB Output is correct
3 Correct 93 ms 27196 KB Output is correct
4 Correct 103 ms 27196 KB Output is correct
5 Correct 592 ms 27196 KB Output is correct
6 Correct 7499 ms 27196 KB Output is correct
7 Execution timed out 15035 ms 29600 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 7928 KB Output is correct
2 Correct 11 ms 7928 KB Output is correct
3 Correct 12 ms 7928 KB Output is correct
4 Correct 14 ms 7928 KB Output is correct
5 Correct 18 ms 8300 KB Output is correct
6 Correct 341 ms 8668 KB Output is correct
7 Correct 88 ms 8668 KB Output is correct
8 Correct 80 ms 8668 KB Output is correct
9 Correct 97 ms 8668 KB Output is correct
10 Correct 242 ms 8704 KB Output is correct
11 Correct 853 ms 9264 KB Output is correct
12 Correct 785 ms 9320 KB Output is correct
13 Correct 44 ms 12648 KB Output is correct
14 Correct 46 ms 13436 KB Output is correct
15 Correct 146 ms 20128 KB Output is correct
16 Correct 86 ms 20128 KB Output is correct
17 Correct 345 ms 22248 KB Output is correct
18 Correct 6761 ms 22248 KB Output is correct
19 Execution timed out 15088 ms 27196 KB Time limit exceeded
20 Halted 0 ms 0 KB -