Submission #296563

# Submission time Handle Problem Language Result Execution time Memory
296563 2020-09-10T16:18:57 Z b00n0rp Split the Attractions (IOI19_split) C++17
40 / 100
190 ms 29488 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vi vector<int>
#define pb push_back
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
 
const int MX = 200005;
 
vi g[MX],adj[MX];
int n,m,par[MX],dep[MX],sz[MX],root;
pii A[MX];
 
bitset<MX> vis;
 
vi ans;

int comp;
int dsusz[2*MX],dsupar[2*MX];
 
void dfs(int u,int p,int d = 0){
	par[u] = p;
	vis[u] = 1;
	dep[u] = d;
	sz[u] = 1;
	for(auto v:g[u]){
		if(vis[v]) continue;
		adj[u].pb(v);
		adj[v].pb(u);
		dfs(v,u,d-1);
		sz[u] += sz[v];
	}
}

void assign(int u,int val){
	vis[u] = 1;
	if(A[val].F){
		ans[u] = A[val].S;
		A[val].F--;
	}
	else ans[u] = A[2].S;
	for(auto v:adj[u]){
		if(!vis[v]) assign(v,val);
	}
}

void assign_graph(int u,int val){
	vis[u] = 1;
	if(A[val].F){
		ans[u] = A[val].S;
		A[val].F--;
	}
	else ans[u] = A[2].S;
	for(auto v:g[u]){
		if(!vis[v]) assign_graph(v,val);
	}
}
 
void dsubuild(int u,int c){
	dsupar[u] = c;
	vis[u] = 1;
	for(auto v:adj[u]){
		if(!vis[v]) dsubuild(v,c);
	}
}

int findpar(int x){
	if(dsupar[x] == x) return x;
	return dsupar[x] = findpar(dsupar[x]);
}

vi find_split(int n, int a, int b, int c, vi p, vi q) {
	::n = n;
	m = p.size();
	A[0] = {a,1};
	A[1] = {b,2};
	A[2] = {c,3};
	sort(A,A+3);
	ans.resize(n);
	REP(i,m){
		g[p[i]].pb(q[i]);
		g[q[i]].pb(p[i]);
	}
	REP(i,2*n) dsupar[i] = i;

	REP(i,n) adj[i].clear();
	vis.reset();
	root = 0;
	dfs(root,root);

	vis.reset();
	REP(i,n){
		if(sz[i] >= A[0].F and n-sz[i] >= A[0].F){
			vis[i] = 1;
			if(sz[i] < n-sz[i]){
				assign(par[i],1);
				assign(i,0);
			}
			else{
				assign(par[i],0);
				assign(i,1);
			}
			return ans;
		}
	}
	REP(i,n){
		int mx = n-sz[i];
		for(auto v:adj[i]){
			if(v != par[i]){
				mx = max(mx,sz[v]);
			}
		}
		if(mx >= a) continue;
		comp = n;
		vis.reset();
		vis[i] = 1;
		for(auto v:adj[i]){
			if(v == par[i]) dsusz[comp] = n-sz[i];
			else dsusz[comp] = sz[v];
			dsubuild(v,comp);
		}
		vis.reset();
		int head = -1;
		REP(j,m){
			if(p[j] == i or q[j] == i) continue;
			int u = findpar(p[j]);
			int v = findpar(q[j]);
			if(u == v) continue;
			if(dsusz[u] > dsusz[v]) swap(u,v);
			dsusz[v] += dsusz[u];
			dsupar[u] = v;
			if(dsusz[v] >= A[0].F){
				head = v;
				break;
			}
		}
		if(head == -1) return vi(n,0);
		vi v1,v2;
		REP(j,n){
			if(j == i or findpar(j) != head) v2.pb(j);
			else v1.pb(j);
		}
		if(dsusz[head] >= A[1].F){
			vis.reset();
			for(auto x:v1) vis[x] = 1;
			assign_graph(v1[0],1);
			vis.reset();
			for(auto x:v2) vis[x] = 1;
			assign_graph(v2[0],0);
		}
		else{
			vis.reset();
			for(auto x:v1) vis[x] = 1;
			assign_graph(v1[0],0);
			vis.reset();
			for(auto x:v2) vis[x] = 1;
			assign_graph(v2[0],1);
		}
		return ans;
	}
}

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:168:1: warning: control reaches end of non-void function [-Wreturn-type]
  168 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9856 KB ok, correct split
2 Correct 7 ms 9728 KB ok, correct split
3 Correct 7 ms 9728 KB ok, correct split
4 Correct 8 ms 9728 KB ok, correct split
5 Correct 8 ms 9728 KB ok, correct split
6 Correct 8 ms 9856 KB ok, correct split
7 Correct 148 ms 28944 KB ok, correct split
8 Correct 177 ms 26744 KB ok, correct split
9 Correct 141 ms 25900 KB ok, correct split
10 Correct 147 ms 29304 KB ok, correct split
11 Correct 145 ms 29488 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB ok, correct split
2 Correct 7 ms 9728 KB ok, correct split
3 Correct 7 ms 9728 KB ok, correct split
4 Correct 159 ms 26744 KB ok, correct split
5 Correct 125 ms 21752 KB ok, correct split
6 Correct 166 ms 29304 KB ok, correct split
7 Correct 148 ms 26488 KB ok, correct split
8 Correct 190 ms 24312 KB ok, correct split
9 Correct 139 ms 21552 KB ok, correct split
10 Correct 94 ms 21932 KB ok, correct split
11 Correct 87 ms 21872 KB ok, correct split
12 Correct 97 ms 22256 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB ok, correct split
2 Correct 126 ms 21752 KB ok, correct split
3 Correct 57 ms 14584 KB ok, correct split
4 Correct 7 ms 9728 KB ok, correct split
5 Correct 140 ms 24208 KB ok, correct split
6 Correct 137 ms 23800 KB ok, correct split
7 Correct 140 ms 23640 KB ok, correct split
8 Correct 139 ms 25004 KB ok, correct split
9 Correct 138 ms 23544 KB ok, correct split
10 Correct 39 ms 13688 KB ok, no valid answer
11 Correct 57 ms 15864 KB ok, no valid answer
12 Correct 108 ms 22004 KB ok, no valid answer
13 Correct 131 ms 21752 KB ok, no valid answer
14 Correct 101 ms 22256 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB ok, correct split
2 Correct 7 ms 9728 KB ok, no valid answer
3 Correct 8 ms 9728 KB ok, correct split
4 Correct 7 ms 9728 KB ok, correct split
5 Correct 8 ms 9728 KB ok, correct split
6 Correct 7 ms 9728 KB ok, correct split
7 Correct 8 ms 9728 KB ok, correct split
8 Correct 7 ms 9728 KB ok, correct split
9 Correct 11 ms 10112 KB ok, correct split
10 Correct 10 ms 10112 KB ok, correct split
11 Correct 8 ms 9728 KB ok, correct split
12 Correct 10 ms 10112 KB ok, correct split
13 Correct 8 ms 9728 KB ok, correct split
14 Correct 7 ms 9728 KB ok, correct split
15 Correct 7 ms 9728 KB ok, correct split
16 Correct 7 ms 9728 KB ok, correct split
17 Correct 7 ms 9728 KB ok, correct split
18 Correct 8 ms 9728 KB ok, correct split
19 Correct 7 ms 9856 KB ok, correct split
20 Correct 8 ms 9856 KB ok, correct split
21 Correct 9 ms 10112 KB ok, correct split
22 Correct 9 ms 10112 KB ok, correct split
23 Correct 10 ms 10112 KB ok, correct split
24 Correct 9 ms 10112 KB ok, correct split
25 Correct 9 ms 10112 KB ok, correct split
26 Incorrect 9 ms 10112 KB jury found a solution, contestant did not
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9856 KB ok, correct split
2 Correct 7 ms 9728 KB ok, correct split
3 Correct 7 ms 9728 KB ok, correct split
4 Correct 8 ms 9728 KB ok, correct split
5 Correct 8 ms 9728 KB ok, correct split
6 Correct 8 ms 9856 KB ok, correct split
7 Correct 148 ms 28944 KB ok, correct split
8 Correct 177 ms 26744 KB ok, correct split
9 Correct 141 ms 25900 KB ok, correct split
10 Correct 147 ms 29304 KB ok, correct split
11 Correct 145 ms 29488 KB ok, correct split
12 Correct 7 ms 9728 KB ok, correct split
13 Correct 7 ms 9728 KB ok, correct split
14 Correct 7 ms 9728 KB ok, correct split
15 Correct 159 ms 26744 KB ok, correct split
16 Correct 125 ms 21752 KB ok, correct split
17 Correct 166 ms 29304 KB ok, correct split
18 Correct 148 ms 26488 KB ok, correct split
19 Correct 190 ms 24312 KB ok, correct split
20 Correct 139 ms 21552 KB ok, correct split
21 Correct 94 ms 21932 KB ok, correct split
22 Correct 87 ms 21872 KB ok, correct split
23 Correct 97 ms 22256 KB ok, correct split
24 Correct 7 ms 9728 KB ok, correct split
25 Correct 126 ms 21752 KB ok, correct split
26 Correct 57 ms 14584 KB ok, correct split
27 Correct 7 ms 9728 KB ok, correct split
28 Correct 140 ms 24208 KB ok, correct split
29 Correct 137 ms 23800 KB ok, correct split
30 Correct 140 ms 23640 KB ok, correct split
31 Correct 139 ms 25004 KB ok, correct split
32 Correct 138 ms 23544 KB ok, correct split
33 Correct 39 ms 13688 KB ok, no valid answer
34 Correct 57 ms 15864 KB ok, no valid answer
35 Correct 108 ms 22004 KB ok, no valid answer
36 Correct 131 ms 21752 KB ok, no valid answer
37 Correct 101 ms 22256 KB ok, no valid answer
38 Correct 7 ms 9728 KB ok, correct split
39 Correct 7 ms 9728 KB ok, no valid answer
40 Correct 8 ms 9728 KB ok, correct split
41 Correct 7 ms 9728 KB ok, correct split
42 Correct 8 ms 9728 KB ok, correct split
43 Correct 7 ms 9728 KB ok, correct split
44 Correct 8 ms 9728 KB ok, correct split
45 Correct 7 ms 9728 KB ok, correct split
46 Correct 11 ms 10112 KB ok, correct split
47 Correct 10 ms 10112 KB ok, correct split
48 Correct 8 ms 9728 KB ok, correct split
49 Correct 10 ms 10112 KB ok, correct split
50 Correct 8 ms 9728 KB ok, correct split
51 Correct 7 ms 9728 KB ok, correct split
52 Correct 7 ms 9728 KB ok, correct split
53 Correct 7 ms 9728 KB ok, correct split
54 Correct 7 ms 9728 KB ok, correct split
55 Correct 8 ms 9728 KB ok, correct split
56 Correct 7 ms 9856 KB ok, correct split
57 Correct 8 ms 9856 KB ok, correct split
58 Correct 9 ms 10112 KB ok, correct split
59 Correct 9 ms 10112 KB ok, correct split
60 Correct 10 ms 10112 KB ok, correct split
61 Correct 9 ms 10112 KB ok, correct split
62 Correct 9 ms 10112 KB ok, correct split
63 Incorrect 9 ms 10112 KB jury found a solution, contestant did not
64 Halted 0 ms 0 KB -