Submission #296493

# Submission time Handle Problem Language Result Execution time Memory
296493 2020-09-10T15:19:08 Z b00n0rp Split the Attractions (IOI19_split) C++17
0 / 100
2000 ms 20856 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 par[MX],dep[MX],sz[MX];
pii A[MX];
 
bitset<MX> vis;
 
vi ans;
 
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);
	}
}
 
vi find_split(int n, int a, int b, int c, vi p, vi q) {
	A[0] = {a,1};
	A[1] = {b,2};
	A[2] = {c,3};
	sort(A,A+3);
	ans.resize(n);
	REP(i,(int)p.size()){
		g[p[i]].pb(q[i]);
		g[q[i]].pb(p[i]);
	}
	int mxd = 0;
	int root = 0;
	REP(i,n){
		mxd = max(mxd,(int)g[i].size());
		if(g[i].size() == 1) root = i;
	}
	dfs(root,root);
	
	if(mxd == 2){
		int cur = root,cnt = 0;
		while(1){
			if(cnt < a) ans[cur] = 1;
			else if(cnt < a+b) ans[cur] = 2;
			else ans[cur] = 3;
			cnt++;
			if(adj[cur].size()) cur = adj[cur][0];
			else break;
		}
		return ans;
	}
	if(a == 1){
		vector<pii> v;
		REP(i,n) v.pb({dep[i],i});
		sort(v.begin(),v.end());
		REP(i,n){
			if(i == 0) ans[v[i].S] = 1;
			else if(i <= b) ans[v[i].S] = 2;
			else ans[v[i].S] = 3;
		}
		return ans;
	}
	vis.reset();
	REP(i,n){
		if(sz[i] >= A[0].F and n-sz[i] >= A[0].F){
			vis[i] = 1;
			assign(par[i],0);
			assign(i,1);
			return ans;
		}
	}
	return vi(n,0);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 9728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 9728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB ok, correct split
2 Incorrect 117 ms 20856 KB invalid split: #1=20000, #2=21840, #3=58160
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB ok, correct split
2 Correct 6 ms 9728 KB ok, no valid answer
3 Execution timed out 2086 ms 9728 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 9728 KB Time limit exceeded
2 Halted 0 ms 0 KB -