Submission #152866

# Submission time Handle Problem Language Result Execution time Memory
152866 2019-09-10T09:22:51 Z tinjyu Split the Attractions (IOI19_split) C++14
40 / 100
98 ms 15220 KB
#include "split.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
using namespace std;
long long int cnt=0,x1[100005],y1[100005],can=0,ans[100005],f[100005],s,e,stop,a[2],b[2],c[2],sum[100005],t[100005],n,m,road[100005],map[1000005][2],tag[100005];
int buildp(int x,int father)
{
	tag[x]=1;
	f[x]=father;
	sum[x]=1;
	int g=road[x];
	while(g!=-1)
	{
		int now=map[g][0];
		if(tag[now]==0)sum[x]+=buildp(now,x);
		g=map[g][1];
	}
	return sum[x];
}
int color(int x,int col)
{
	if(s==e)return 0;
	s++;
	ans[x]=col;
	int g=road[x];
	while(g!=-1)
	{
		if(s==e)return 0;
		int now=map[g][0];
		if(now!=f[x] && now!=stop)color(now,col);
		g=map[g][1];
	}
}
int find(int x,int father)
{
	if(sum[x]>=a[0] && father>=b[0])
	{	
		can=1;
		stop=f[x];
		s=0;
		e=a[0];
		color(x,a[1]);
		stop=x;
		s=0;
		e=b[0];
		color(0,b[1]);
		return 0;
	}
	if(father>=a[0] && sum[x]>=b[0])
	{
		can=1;
		stop=x;
		s=0;
		e=a[0];
		color(0,a[1]);
		stop=f[x];
		s=0;
		e=b[0];
		color(x,b[1]);
		return 0;
	}
	int g=road[x];
	while(g!=-1)
	{
		int now=map[g][0];
		if(now!=f[x])find(now,father+(sum[x]-sum[now]));
		if(can==1)return 0;
		g=map[g][1];
	}
}
int dfs(int x)
{
	int g=road[x];
	tag[x]=1;
	while(g!=-1)
	{
		int now=map[g][0];
		if(tag[now]==0)
		{
			y1[cnt]=x;
			x1[cnt]=now;
			cnt++;
			dfs(now);
		}
		g=map[g][1];
	}
	return 0;
}
vector<int> find_split(int N, int A, int B, int C, vector<int> p, vector<int> q) {
	a[0]=A;
	a[1]=1;
	b[0]=B;
	b[1]=2;
	c[0]=C;
	c[1]=3;
	srand (time(NULL));

	if(b[0]<=a[0] && b[0]<=c[0])
	{
		swap(a[0],b[0]);
		swap(a[1],b[1]);
	}
	if(c[0]<=b[0] && c[0]<=a[0])
	{
		swap(a[0],c[0]);
		swap(a[1],c[1]);
	}
	if(c[0]<=b[0])
	{
		swap(b[0],c[0]);
		swap(b[1],c[1]);
	}
 	;
	n=N;
	m=q.size();
	for(int i=0;i<=n;i++)road[i]=-1;
	for(int i=0;i<m;i++)
	{
		map[i*2][0]=p[i];
		map[i*2][1]=road[q[i]];
		road[q[i]]=i*2;
		map[i*2+1][0]=q[i];
		map[i*2+1][1]=road[p[i]];
		road[p[i]]=i*2+1;
	}
	dfs(rand()%n);
	for(int i=0;i<cnt;i++)
	{
		p[i]=x1[i];
		q[i]=y1[i];
	}
	for(int i=0;i<=n;i++)
	{
		road[i]=-1;
		tag[i]=0;
	}
	for(int i=0;i<cnt;i++)
	{
		map[i*2][0]=p[i];
		map[i*2][1]=road[q[i]];
		road[q[i]]=i*2;
		map[i*2+1][0]=q[i];
		map[i*2+1][1]=road[p[i]];
		road[p[i]]=i*2+1;
	}
	buildp(0,-1);
	find(0,0);
	vector<int> res(n);
	if(can==0)return res;
	for(int i=0;i<n;i++)
	{
		res[i]=ans[i];
		if(res[i]==0)res[i]=c[1];
	} 
	return res;
}

Compilation message

split.cpp: In function 'int color(int, int)':
split.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
split.cpp: In function 'int find(int, int)':
split.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 376 KB ok, correct split
4 Correct 2 ms 376 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 74 ms 13916 KB ok, correct split
8 Correct 66 ms 12664 KB ok, correct split
9 Correct 69 ms 13560 KB ok, correct split
10 Correct 66 ms 13304 KB ok, correct split
11 Correct 86 ms 14072 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 376 KB ok, correct split
4 Correct 82 ms 13836 KB ok, correct split
5 Correct 64 ms 10844 KB ok, correct split
6 Correct 68 ms 13304 KB ok, correct split
7 Correct 68 ms 12920 KB ok, correct split
8 Correct 98 ms 15220 KB ok, correct split
9 Correct 64 ms 11000 KB ok, correct split
10 Correct 51 ms 10876 KB ok, correct split
11 Correct 52 ms 10872 KB ok, correct split
12 Correct 55 ms 10872 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB ok, correct split
2 Correct 70 ms 11024 KB ok, correct split
3 Correct 26 ms 4516 KB ok, correct split
4 Correct 2 ms 376 KB ok, correct split
5 Correct 68 ms 11896 KB ok, correct split
6 Correct 66 ms 12284 KB ok, correct split
7 Correct 70 ms 12024 KB ok, correct split
8 Correct 71 ms 12408 KB ok, correct split
9 Correct 66 ms 12024 KB ok, correct split
10 Correct 22 ms 3704 KB ok, no valid answer
11 Correct 32 ms 5240 KB ok, no valid answer
12 Correct 62 ms 10104 KB ok, no valid answer
13 Correct 66 ms 10208 KB ok, no valid answer
14 Correct 55 ms 10104 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB ok, correct split
2 Correct 2 ms 376 KB ok, no valid answer
3 Correct 2 ms 376 KB ok, correct split
4 Correct 2 ms 376 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 2 ms 376 KB ok, correct split
8 Correct 2 ms 376 KB ok, correct split
9 Correct 4 ms 764 KB ok, correct split
10 Correct 4 ms 760 KB ok, correct split
11 Correct 2 ms 376 KB ok, correct split
12 Correct 4 ms 760 KB ok, correct split
13 Correct 2 ms 376 KB ok, correct split
14 Correct 2 ms 376 KB ok, correct split
15 Correct 2 ms 376 KB ok, correct split
16 Correct 2 ms 376 KB ok, correct split
17 Correct 2 ms 376 KB ok, correct split
18 Correct 2 ms 376 KB ok, correct split
19 Correct 2 ms 376 KB ok, correct split
20 Correct 3 ms 504 KB ok, correct split
21 Correct 4 ms 628 KB ok, correct split
22 Correct 3 ms 712 KB ok, correct split
23 Correct 3 ms 764 KB ok, correct split
24 Correct 3 ms 632 KB ok, correct split
25 Correct 3 ms 632 KB ok, correct split
26 Incorrect 4 ms 760 KB jury found a solution, contestant did not
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 376 KB ok, correct split
4 Correct 2 ms 376 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 74 ms 13916 KB ok, correct split
8 Correct 66 ms 12664 KB ok, correct split
9 Correct 69 ms 13560 KB ok, correct split
10 Correct 66 ms 13304 KB ok, correct split
11 Correct 86 ms 14072 KB ok, correct split
12 Correct 2 ms 380 KB ok, correct split
13 Correct 2 ms 376 KB ok, correct split
14 Correct 2 ms 376 KB ok, correct split
15 Correct 82 ms 13836 KB ok, correct split
16 Correct 64 ms 10844 KB ok, correct split
17 Correct 68 ms 13304 KB ok, correct split
18 Correct 68 ms 12920 KB ok, correct split
19 Correct 98 ms 15220 KB ok, correct split
20 Correct 64 ms 11000 KB ok, correct split
21 Correct 51 ms 10876 KB ok, correct split
22 Correct 52 ms 10872 KB ok, correct split
23 Correct 55 ms 10872 KB ok, correct split
24 Correct 2 ms 376 KB ok, correct split
25 Correct 70 ms 11024 KB ok, correct split
26 Correct 26 ms 4516 KB ok, correct split
27 Correct 2 ms 376 KB ok, correct split
28 Correct 68 ms 11896 KB ok, correct split
29 Correct 66 ms 12284 KB ok, correct split
30 Correct 70 ms 12024 KB ok, correct split
31 Correct 71 ms 12408 KB ok, correct split
32 Correct 66 ms 12024 KB ok, correct split
33 Correct 22 ms 3704 KB ok, no valid answer
34 Correct 32 ms 5240 KB ok, no valid answer
35 Correct 62 ms 10104 KB ok, no valid answer
36 Correct 66 ms 10208 KB ok, no valid answer
37 Correct 55 ms 10104 KB ok, no valid answer
38 Correct 2 ms 376 KB ok, correct split
39 Correct 2 ms 376 KB ok, no valid answer
40 Correct 2 ms 376 KB ok, correct split
41 Correct 2 ms 376 KB ok, correct split
42 Correct 2 ms 376 KB ok, correct split
43 Correct 2 ms 376 KB ok, correct split
44 Correct 2 ms 376 KB ok, correct split
45 Correct 2 ms 376 KB ok, correct split
46 Correct 4 ms 764 KB ok, correct split
47 Correct 4 ms 760 KB ok, correct split
48 Correct 2 ms 376 KB ok, correct split
49 Correct 4 ms 760 KB ok, correct split
50 Correct 2 ms 376 KB ok, correct split
51 Correct 2 ms 376 KB ok, correct split
52 Correct 2 ms 376 KB ok, correct split
53 Correct 2 ms 376 KB ok, correct split
54 Correct 2 ms 376 KB ok, correct split
55 Correct 2 ms 376 KB ok, correct split
56 Correct 2 ms 376 KB ok, correct split
57 Correct 3 ms 504 KB ok, correct split
58 Correct 4 ms 628 KB ok, correct split
59 Correct 3 ms 712 KB ok, correct split
60 Correct 3 ms 764 KB ok, correct split
61 Correct 3 ms 632 KB ok, correct split
62 Correct 3 ms 632 KB ok, correct split
63 Incorrect 4 ms 760 KB jury found a solution, contestant did not
64 Halted 0 ms 0 KB -