답안 #313954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313954 2020-10-17T15:12:11 Z CaroLinda Amusement Park (JOI17_amusement_park) C++14
100 / 100
37 ms 6156 KB
#include "Joi.h"
#include <bits/stdc++.h>

#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ll long long
#define pii pair<int,int>

const int MAXN = 1e4+10 ;

using namespace std ;

int val[MAXN] , sub[MAXN] ;
int ini[MAXN] , fim[MAXN] ;
int group[MAXN] , father[MAXN] ;
vector<int> adj[MAXN] ;
vector<int> tree[MAXN] ;
bool freq[65] ;
bool mark[MAXN] ;

void dfs1(int x)
{
	sub[x] = 1 ;

	for(auto e : adj[x] ) 
	{
		if( sub[e] > 0) continue ;

		dfs1(e) ;

		tree[x].push_back(e) ;
		sub[x] += sub[e] ;

		tree[e].push_back(x) ;
		father[e] = x ;

	}

}

int qtd ;
void dfs2(int x)
{
	if(qtd <= 0) return ;

	freq[ val[x] ] = true ;
	qtd-- ;

	for(auto e : tree[x] ) 
	{
		if(qtd <= 0) return ;

		if( group[e] == group[x]  && e != father[x] && !freq[ val[e] ] )
			dfs2(e) ;
	}

	if(qtd <= 0) return ;

	if(!freq[val[father[x]]])
		dfs2(father[x]) ;

}

int isOn(int i, ll x ) { return ((1LL<<i)&x) != 0; }

void Joi(int N, int M, int A[], int B[], long long X, int T) 
{

	for(int i = 0 ; i < N ; i++ ) val[i] = -1 ;
	father[0] = -1 ;

	for(int i= 0 ; i < M ; i++ ) 
	{
		adj[ A[i] ].push_back( B[i] ) ;
		adj[ B[i] ].push_back( A[i] ) ;
	}

	dfs1(0) ;

	vector<int> fila(1,0) ;
	int ini = 0 ; 

	while( ini < sz(fila) )
	{
		int x = fila[ini++] ;

		vector<int> miniFila(1,x) ;
		int miniIni = 0 ;

		if( sub[x] >= 60 )
		{

			while(miniIni < sz(miniFila) && miniIni < 60 )
			{
				int miniX = miniFila[miniIni] ;
				val[ miniX ] = miniIni++ ;
				group[miniX] = -(x+1) ;

				for(auto e : tree[miniX] ) 
					if(val[e] == -1)
						miniFila.push_back(e) ;
			}

			for(int i = miniIni ; i < sz(miniFila) ; i++ ) 
				fila.push_back(miniFila[i]) ;
		}
		else 
		{
			qtd = 60 - sub[x] ;
			for(int i = 0 ; i < 60 ; i++ ) freq[i] = false ;

			dfs2( father[x] ) ;

			while(miniIni < sz(miniFila))
			{
				int miniX = miniFila[miniIni++] ;
				group[miniX] = x+1 ;

				for(int i = 0 ; i < 60 ; i++ )
					if(freq[i] == false )
					{
						freq[i] = true ;
						val[ miniX ] = i ;
						break ;
					}

				for(auto e : tree[miniX] ) 
					if(val[e] == -1)
						miniFila.push_back(e) ;
			}

		}

	}

	//for(int i = 0 ;i < N ; i++ ) cout << val[i] << endl ;

  	for(int i = 0 ; i < N ; i++ ) 
  		MessageBoard( i, isOn(val[i] , X) ) ;

}
#include "Ioi.h"
#include <bits/stdc++.h>

#define debug printf
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ll long long

const int MAX = 1e4+10 ;

using namespace std ;

int valor[MAX] , subarvore[MAX ] ;
int pai[MAX] , grupo[MAX] ;
int achei[65] ;
bool frequencia[65] ;
bool vis[MAX] ;
vector<int> graph[MAX] , arvore[MAX] ;

void dfs11(int x)
{
	subarvore[x] = 1 ;

	for(auto e : graph[x] ) 
	{
		if( subarvore[e] > 0) continue ;

		dfs11(e) ;

		arvore[x].push_back(e) ;
		subarvore[x] += subarvore[e] ;

		arvore[e].push_back(x) ;
		pai[e] = x ;

	}

}

int quantidade ;
void dfs22(int x)
{
	if(quantidade <= 0) return ;

	frequencia[ valor[x] ] = true ;
	quantidade-- ;

	for(auto e : arvore[x] ) 
	{
		if(quantidade <= 0) return ;

		if( grupo[e] == grupo[x] && e != pai[x] && !frequencia[valor[e]] )
			dfs22(e) ;
	}

	if(quantidade <= 0) return ;

	if(!frequencia[valor[pai[x]]])
		dfs22(pai[x] ) ;

}

int qtdd = 60 ;
void dfsTraversal(int x)
{
	if(qtdd <= 0 ) return ;

	vis[x] = true ;
	qtdd-- ;

	for(auto e : arvore[x])
	{
		if(qtdd <= 0 ) return;

		if(e == pai[x] || grupo[e] != grupo[x] || vis[e] )  continue ;

		achei[ valor[e] ] = Move(e);
		dfsTraversal(e) ;

	}

	if(x == 0 || qtdd <= 0 ) return ;

	achei[ valor[ pai[x] ] ] = Move(pai[x]) ;

	if(!vis[ pai[x] ])
		dfsTraversal(pai[x]) ;

}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) 
{

	for(int i = 0 ; i < N ; i++ ) valor[i] = -1 ;
	pai[0] = -1 ;

	for(int i= 0 ; i < M ; i++ ) 
	{
		graph[ A[i] ].push_back( B[i] ) ;
		graph[ B[i] ].push_back( A[i] ) ;
	}

	dfs11(0) ;

	vector<int> fila(1,0) ;
	int ini = 0 ; 

	while( ini < sz(fila) )
	{
		int x = fila[ini++] ;

		vector<int> miniFila(1,x) ;
		int miniIni = 0 ;

		if( subarvore[x] >= 60 )
		{

			while(miniIni < sz(miniFila) && miniIni < 60 )
			{
				int miniX = miniFila[miniIni] ;
				valor[ miniX ] = miniIni++ ;
				grupo[miniX] = -(x+1) ;

				for(auto e : arvore[miniX] ) 
					if(valor[e] == -1)
						miniFila.push_back(e) ;
			}

			for(int i = miniIni ; i < sz(miniFila) ; i++ ) 
				fila.push_back(miniFila[i]) ;
		}
		else 
		{
			quantidade = 60 - subarvore[x] ;
			for(int i = 0 ; i < 60 ; i++ ) frequencia[i] = false ;

			dfs22( pai[x] );

			while(miniIni < sz(miniFila))
			{
				int miniX = miniFila[miniIni++] ;
				grupo[miniX] = x+1 ;

				for(int i = 0 ; i < 60 ; i++ )
					if(frequencia[i] == false )
					{
						frequencia[i] = true ;
						valor[ miniX ] = i ;
						break ;
					}

				for(auto e : arvore[miniX] ) 
					if(valor[e] == -1)
						miniFila.push_back(e) ;
			}

		}

	}

	achei[ valor[P] ] = V ;

	for(int i = 0 ; i< N ; i++ ) vis[i] = false ;

	dfsTraversal(P) ;

	ll resp = 0LL ;
	for(int i = 0 ;i < 60 ; i++ )
		resp += (1LL<<i) * achei[i] ;

	return resp ;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1804 KB Output is correct
2 Correct 2 ms 1796 KB Output is correct
3 Correct 2 ms 1932 KB Output is correct
4 Correct 2 ms 1800 KB Output is correct
5 Correct 2 ms 1672 KB Output is correct
6 Correct 2 ms 1672 KB Output is correct
7 Correct 2 ms 2036 KB Output is correct
8 Correct 2 ms 1840 KB Output is correct
9 Correct 2 ms 1928 KB Output is correct
10 Correct 2 ms 1672 KB Output is correct
11 Correct 6 ms 2344 KB Output is correct
12 Correct 2 ms 1812 KB Output is correct
13 Correct 2 ms 2048 KB Output is correct
14 Correct 2 ms 2052 KB Output is correct
15 Correct 2 ms 1948 KB Output is correct
16 Correct 2 ms 2052 KB Output is correct
17 Correct 2 ms 2048 KB Output is correct
18 Correct 2 ms 1948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 5664 KB Output is correct
2 Correct 33 ms 5652 KB Output is correct
3 Correct 34 ms 6156 KB Output is correct
4 Correct 27 ms 4268 KB Output is correct
5 Correct 25 ms 4800 KB Output is correct
6 Correct 23 ms 4780 KB Output is correct
7 Correct 23 ms 4652 KB Output is correct
8 Correct 23 ms 4816 KB Output is correct
9 Correct 23 ms 4780 KB Output is correct
10 Correct 37 ms 4832 KB Output is correct
11 Correct 34 ms 4828 KB Output is correct
12 Correct 22 ms 4116 KB Output is correct
13 Correct 23 ms 4364 KB Output is correct
14 Correct 23 ms 4204 KB Output is correct
15 Correct 25 ms 4284 KB Output is correct
16 Correct 25 ms 4284 KB Output is correct
17 Correct 25 ms 4140 KB Output is correct
18 Correct 27 ms 4268 KB Output is correct
19 Correct 30 ms 4276 KB Output is correct
20 Correct 20 ms 5148 KB Output is correct
21 Correct 17 ms 4784 KB Output is correct
22 Correct 23 ms 4536 KB Output is correct
23 Correct 22 ms 4684 KB Output is correct
24 Correct 23 ms 4772 KB Output is correct
25 Correct 20 ms 4740 KB Output is correct
26 Correct 20 ms 4832 KB Output is correct
27 Correct 20 ms 4856 KB Output is correct
28 Correct 23 ms 4652 KB Output is correct
29 Correct 19 ms 4780 KB Output is correct
30 Correct 19 ms 4524 KB Output is correct
31 Correct 2 ms 1672 KB Output is correct
32 Correct 2 ms 1800 KB Output is correct
33 Correct 2 ms 1936 KB Output is correct
34 Correct 2 ms 1800 KB Output is correct
35 Correct 2 ms 1800 KB Output is correct
36 Correct 2 ms 1812 KB Output is correct
37 Correct 2 ms 1800 KB Output is correct
38 Correct 2 ms 1928 KB Output is correct
39 Correct 2 ms 1816 KB Output is correct
40 Correct 2 ms 1812 KB Output is correct
41 Correct 2 ms 1672 KB Output is correct
42 Correct 2 ms 1928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1812 KB Output is correct
2 Correct 2 ms 1800 KB Output is correct
3 Correct 2 ms 1796 KB Output is correct
4 Correct 4 ms 2468 KB Output is correct
5 Correct 4 ms 2468 KB Output is correct
6 Correct 4 ms 2584 KB Output is correct
7 Correct 4 ms 2340 KB Output is correct
8 Correct 4 ms 2720 KB Output is correct
9 Correct 18 ms 5504 KB Output is correct
10 Correct 17 ms 5200 KB Output is correct
11 Correct 20 ms 5624 KB Output is correct
12 Correct 2 ms 1676 KB Output is correct
13 Correct 2 ms 1676 KB Output is correct
14 Correct 2 ms 1816 KB Output is correct
15 Correct 2 ms 1936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 5528 KB Output is correct
2 Correct 36 ms 5476 KB Output is correct
3 Correct 33 ms 5644 KB Output is correct
4 Correct 33 ms 4312 KB Output is correct
5 Correct 22 ms 5164 KB Output is correct
6 Correct 24 ms 4952 KB Output is correct
7 Correct 24 ms 4944 KB Output is correct
8 Correct 23 ms 4524 KB Output is correct
9 Correct 23 ms 4776 KB Output is correct
10 Correct 35 ms 4752 KB Output is correct
11 Correct 37 ms 4620 KB Output is correct
12 Correct 20 ms 4252 KB Output is correct
13 Correct 23 ms 4108 KB Output is correct
14 Correct 22 ms 4332 KB Output is correct
15 Correct 24 ms 4280 KB Output is correct
16 Correct 25 ms 4284 KB Output is correct
17 Correct 25 ms 4268 KB Output is correct
18 Correct 25 ms 4268 KB Output is correct
19 Correct 25 ms 4268 KB Output is correct
20 Correct 17 ms 5156 KB Output is correct
21 Correct 18 ms 5032 KB Output is correct
22 Correct 22 ms 4852 KB Output is correct
23 Correct 22 ms 4668 KB Output is correct
24 Correct 20 ms 4620 KB Output is correct
25 Correct 20 ms 4672 KB Output is correct
26 Correct 22 ms 4796 KB Output is correct
27 Correct 20 ms 5044 KB Output is correct
28 Correct 22 ms 4736 KB Output is correct
29 Correct 19 ms 4388 KB Output is correct
30 Correct 20 ms 4892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 5608 KB Output is correct
2 Correct 34 ms 5476 KB Output is correct
3 Correct 33 ms 5476 KB Output is correct
4 Correct 25 ms 4268 KB Output is correct
5 Correct 20 ms 5068 KB Output is correct
6 Correct 24 ms 4616 KB Output is correct
7 Correct 23 ms 4536 KB Output is correct
8 Correct 23 ms 4684 KB Output is correct
9 Correct 23 ms 4556 KB Output is correct
10 Correct 36 ms 4564 KB Output is correct
11 Correct 37 ms 4584 KB Output is correct
12 Correct 23 ms 4112 KB Output is correct
13 Correct 23 ms 4104 KB Output is correct
14 Correct 23 ms 4144 KB Output is correct
15 Correct 25 ms 4284 KB Output is correct
16 Correct 25 ms 4372 KB Output is correct
17 Correct 25 ms 4548 KB Output is correct
18 Correct 25 ms 4524 KB Output is correct
19 Correct 26 ms 4336 KB Output is correct
20 Correct 17 ms 4924 KB Output is correct
21 Correct 17 ms 5180 KB Output is correct
22 Correct 22 ms 4868 KB Output is correct
23 Correct 22 ms 5028 KB Output is correct
24 Correct 20 ms 4796 KB Output is correct
25 Correct 26 ms 4896 KB Output is correct
26 Correct 20 ms 4608 KB Output is correct
27 Correct 22 ms 5040 KB Output is correct
28 Correct 24 ms 5052 KB Output is correct
29 Correct 19 ms 4772 KB Output is correct
30 Correct 19 ms 4656 KB Output is correct
31 Correct 2 ms 1804 KB Output is correct
32 Correct 2 ms 1808 KB Output is correct
33 Correct 2 ms 1968 KB Output is correct
34 Correct 2 ms 1672 KB Output is correct
35 Correct 2 ms 1800 KB Output is correct
36 Correct 2 ms 1800 KB Output is correct
37 Correct 2 ms 1808 KB Output is correct
38 Correct 2 ms 1812 KB Output is correct
39 Correct 2 ms 1808 KB Output is correct
40 Correct 2 ms 1800 KB Output is correct
41 Correct 2 ms 1800 KB Output is correct
42 Correct 2 ms 1820 KB Output is correct