Submission #342913

# Submission time Handle Problem Language Result Execution time Memory
342913 2021-01-03T08:12:32 Z inwbear Split the Attractions (IOI19_split) C++14
0 / 100
4 ms 4972 KB
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
vector<int>v[100005],cn[100005];
vector<pii>gr;
bitset<100005>vis;
int ch[100005],mn,pos,rr,re[100005];

void dfs(int N)
{
	vis[N]=true;
	ch[N]=1;
	for(int i=0;i<v[N].size();i++)
	{
		if((!vis[v[N][i]])&&re[v[N][i]]==0)
		{
			dfs(v[N][i]);
			ch[N]+=ch[v[N][i]];
			cn[N].pb(v[N][i]);
		}
	}
	//printf("[%d %d]\n",N,ch[N]);
	return;
}

void grdiv(int N,int ty)
{
	if(rr>=gr[ty].F||re[N]!=0)return;
	ch[N]=0;
	rr++,re[N]=gr[ty].S;
	for(int i=0;i<cn[N].size();i++)
	{
		grdiv(cn[N][i],ty);
	}
	return;
}

vector<int>find_split(int n,int a,int b,int c,vector<int>p,vector<int>q)
{
	vector<int>ans(n);
	gr.pb({a,1});
	gr.pb({b,2});
	gr.pb({c,3});
	sort(all(gr));
	for(int i=0;i<p.size();i++)
	{
		v[p[i]].pb(q[i]);
		v[q[i]].pb(p[i]);
	}
	dfs(0);
	mn=imx,rr=1;
	for(int i=0;i<n;i++)
	{
		if(ch[i]>=gr[0].F&&ch[i]<mn)
		{
			mn=ch[i];
			pos=i;
		}
	}
	re[pos]=gr[0].S,ch[pos]=0;
	for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],0);
	for(int i=0;i<n;i++)cn[i].clear(),vis[i]=false;
	dfs(0);
	mn=imx,rr=1;
	for(int i=0;i<n;i++)
	{
		if(ch[i]>=gr[0].F&&ch[i]<mn)
		{
			mn=ch[i];
			pos=i;
		}
	}
	if(mn!=imx)
	{
		re[pos]=gr[1].S,ch[pos]=0;
		for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],1);
		for(int i=0;i<n;i++)
		{
			//printf("%d ",re[i]);
			if(re[i]==0)ans[i]=gr[2].S;
			else ans[i]=re[i];
		}
		//printf("\n");
	}
	return ans;
}

Compilation message

split.cpp: In function 'void dfs(int)':
split.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i<v[N].size();i++)
      |              ~^~~~~~~~~~~~
split.cpp: In function 'void grdiv(int, int)':
split.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i=0;i<cn[N].size();i++)
      |              ~^~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:55:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i=0;i<p.size();i++)
      |              ~^~~~~~~~~
split.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],0);
      |              ~^~~~~~~~~~~~~~~
split.cpp:86:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],1);
      |               ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB ok, correct split
2 Correct 3 ms 4972 KB ok, correct split
3 Correct 3 ms 4972 KB ok, correct split
4 Correct 3 ms 4972 KB ok, correct split
5 Correct 3 ms 4972 KB ok, correct split
6 Incorrect 3 ms 4972 KB invalid split: #1=20, #2=20, #3=60
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB ok, correct split
2 Correct 3 ms 4972 KB ok, correct split
3 Incorrect 4 ms 4972 KB invalid split: #1=1, #2=1, #3=3
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4972 KB invalid split: #1=1, #2=1, #3=3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4972 KB invalid split: #1=5, #2=2, #3=2
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB ok, correct split
2 Correct 3 ms 4972 KB ok, correct split
3 Correct 3 ms 4972 KB ok, correct split
4 Correct 3 ms 4972 KB ok, correct split
5 Correct 3 ms 4972 KB ok, correct split
6 Incorrect 3 ms 4972 KB invalid split: #1=20, #2=20, #3=60
7 Halted 0 ms 0 KB -