Submission #299231

# Submission time Handle Problem Language Result Execution time Memory
299231 2020-09-14T15:14:59 Z TMJN Split the Attractions (IOI19_split) C++17
40 / 100
123 ms 15992 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;

int c[100000],par[100000];
vector<int>e[100000];
vector<int>res;

void dfs(int x,int from){
	par[x]=from;
	c[x]=1;
	for(int i:e[x]){
		if(i==from)continue;
		dfs(i,x);
		c[x]+=c[i];
	}
}

vector<int>find_split(int n,int aaa,int bbb,int ccc,vector<int>p,vector<int>q){
	res=vector<int>(n,0);
	pair<int,int>P[3];
	P[0]={aaa,1};
	P[1]={bbb,2};
	P[2]={ccc,3};
	sort(P,P+3);
	for(int i=0;i<p.size();i++){
		e[p[i]].push_back(q[i]);
		e[q[i]].push_back(p[i]);
	}
	if(P[0].first==1){
		queue<int>que;
		que.push(0);
		while(P[1].first){
			int x=que.front();
			que.pop();
			if(res[x])continue;
			res[x]=P[1].second;
			P[1].first--;
			for(int i:e[x]){
				que.push(i);
			}
		}
		for(int i=0;i<n;i++){
			if(!res[i]){
				res[i]=P[0].second;
				break;
			}
		}
		for(int i=0;i<n;i++){
			if(!res[i]){
				res[i]=P[2].second;
			}
		}
	}
	else if(p.size()==n-1){
		dfs(0,0);
		pair<int,int>mn={0xE869120,-1};
		for(int i=0;i<n;i++){
			if(c[i]>=P[0].first){
				mn=min(mn,{c[i],i});
			}
			if(n-c[i]>=P[0].first){
				mn=min(mn,{n-c[i],-i});
			}
		}
		if(mn.second==0){
		}
		else if(mn.second>0){
			queue<int>que;
			que.push(mn.second);
			res[par[mn.second]]=0xE869120;
			while(P[0].first){
				int x=que.front();
				que.pop();
				if(!res[x]){
					res[x]=P[0].second;
						P[0].first--;
					for(int i:e[x]){
						que.push(i);
					}
				}
			}
			res[par[mn.second]]=0;
			while(!que.empty())que.pop();
			que.push(par[mn.second]);
			while(!que.empty()&&P[1].first){
				int x=que.front();
				que.pop();
				if(!res[x]){
					res[x]=P[1].second;
					P[1].first--;
					for(int i:e[x]){
						que.push(i);
					}
				}
			}
			if(!P[1].first){
				for(int i=0;i<n;i++){
					if(!res[i])res[i]=P[2].second;
				}
			}
			else{
				for(int i=0;i<n;i++){
					res[i]=0;
				}
			}
		}
		else{
			queue<int>que;
			que.push(par[-mn.second]);
			res[-mn.second]=0xE869120;
			while(P[0].first){
				int x=que.front();
				que.pop();
				if(!res[x]){
					res[x]=P[0].second;
					P[0].first--;
					for(int i:e[x]){
						que.push(i);
					}
				}
			}
			res[-mn.second]=0;
			while(!que.empty())que.pop();
			que.push(-mn.second);
			while(!que.empty()&&P[1].first){
				int x=que.front();
				que.pop();
				if(!res[x]){
					res[x]=P[1].second;
					P[1].first--;
					for(int i:e[x]){
						que.push(i);
					}
				}
			}
			if(!P[1].first){
				for(int i=0;i<n;i++){
					if(!res[i])res[i]=P[2].second;
				}
			}
			else{
				for(int i=0;i<n;i++){
					res[i]=0;
				}
			}
		}
	}
	else if(p.size()==n){
		queue<int>que;
		que.push(0);
		while(P[0].first){
			int x=que.front();
			que.pop();
			if(!res[x]){
				P[0].first--;
				res[x]=P[0].second;
				for(int i:e[x]){
					que.push(i);
				}
			}
		}
		while(!que.empty())que.pop();
		for(int i=0;i<n;i++){
			if(!res[i]){
				que.push(i);
				while(P[1].first){
					int x=que.front();
					que.pop();
					if(!res[x]){
						P[1].first--;
						res[x]=P[1].second;
						for(int j:e[x]){
							que.push(j);
						}
					}
				}
				break;
			}
		}
		for(int i=0;i<n;i++){
			if(!res[i])res[i]=P[2].second;
		}
	}
	return res;
}

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i=0;i<p.size();i++){
      |              ~^~~~~~~~~
split.cpp:55:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |  else if(p.size()==n-1){
      |          ~~~~~~~~^~~~~
split.cpp:149:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  149 |  else if(p.size()==n){
      |          ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB ok, correct split
2 Correct 2 ms 2688 KB ok, correct split
3 Correct 2 ms 2688 KB ok, correct split
4 Correct 2 ms 2688 KB ok, correct split
5 Correct 2 ms 2688 KB ok, correct split
6 Correct 2 ms 2688 KB ok, correct split
7 Correct 98 ms 15992 KB ok, correct split
8 Correct 78 ms 9336 KB ok, correct split
9 Correct 113 ms 13688 KB ok, correct split
10 Correct 76 ms 9336 KB ok, correct split
11 Correct 85 ms 9336 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB ok, correct split
2 Correct 2 ms 2688 KB ok, correct split
3 Correct 2 ms 2688 KB ok, correct split
4 Correct 96 ms 9336 KB ok, correct split
5 Correct 78 ms 8312 KB ok, correct split
6 Correct 84 ms 8184 KB ok, correct split
7 Correct 76 ms 8184 KB ok, correct split
8 Correct 123 ms 10564 KB ok, correct split
9 Correct 80 ms 8184 KB ok, correct split
10 Correct 59 ms 8768 KB ok, correct split
11 Correct 60 ms 8640 KB ok, correct split
12 Correct 62 ms 8640 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB ok, correct split
2 Correct 86 ms 9080 KB ok, correct split
3 Correct 28 ms 5240 KB ok, correct split
4 Correct 2 ms 2688 KB ok, correct split
5 Correct 94 ms 11000 KB ok, correct split
6 Correct 92 ms 10744 KB ok, correct split
7 Correct 94 ms 10616 KB ok, correct split
8 Correct 99 ms 11896 KB ok, correct split
9 Correct 91 ms 10488 KB ok, correct split
10 Correct 26 ms 4864 KB ok, no valid answer
11 Correct 35 ms 6008 KB ok, no valid answer
12 Correct 68 ms 9332 KB ok, no valid answer
13 Correct 79 ms 9080 KB ok, no valid answer
14 Correct 64 ms 9408 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB jury found a solution, contestant did not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB ok, correct split
2 Correct 2 ms 2688 KB ok, correct split
3 Correct 2 ms 2688 KB ok, correct split
4 Correct 2 ms 2688 KB ok, correct split
5 Correct 2 ms 2688 KB ok, correct split
6 Correct 2 ms 2688 KB ok, correct split
7 Correct 98 ms 15992 KB ok, correct split
8 Correct 78 ms 9336 KB ok, correct split
9 Correct 113 ms 13688 KB ok, correct split
10 Correct 76 ms 9336 KB ok, correct split
11 Correct 85 ms 9336 KB ok, correct split
12 Correct 2 ms 2688 KB ok, correct split
13 Correct 2 ms 2688 KB ok, correct split
14 Correct 2 ms 2688 KB ok, correct split
15 Correct 96 ms 9336 KB ok, correct split
16 Correct 78 ms 8312 KB ok, correct split
17 Correct 84 ms 8184 KB ok, correct split
18 Correct 76 ms 8184 KB ok, correct split
19 Correct 123 ms 10564 KB ok, correct split
20 Correct 80 ms 8184 KB ok, correct split
21 Correct 59 ms 8768 KB ok, correct split
22 Correct 60 ms 8640 KB ok, correct split
23 Correct 62 ms 8640 KB ok, correct split
24 Correct 2 ms 2688 KB ok, correct split
25 Correct 86 ms 9080 KB ok, correct split
26 Correct 28 ms 5240 KB ok, correct split
27 Correct 2 ms 2688 KB ok, correct split
28 Correct 94 ms 11000 KB ok, correct split
29 Correct 92 ms 10744 KB ok, correct split
30 Correct 94 ms 10616 KB ok, correct split
31 Correct 99 ms 11896 KB ok, correct split
32 Correct 91 ms 10488 KB ok, correct split
33 Correct 26 ms 4864 KB ok, no valid answer
34 Correct 35 ms 6008 KB ok, no valid answer
35 Correct 68 ms 9332 KB ok, no valid answer
36 Correct 79 ms 9080 KB ok, no valid answer
37 Correct 64 ms 9408 KB ok, no valid answer
38 Incorrect 2 ms 2688 KB jury found a solution, contestant did not
39 Halted 0 ms 0 KB -