답안 #69444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69444 2018-08-20T21:32:44 Z IvanC Amusement Park (JOI17_amusement_park) C++17
79 / 100
72 ms 45528 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10011;
const int MOD = 60;

static vector<int> grafo[MAXN],digitos;
static int dfs_num[MAXN],nivel[MAXN],dfsCount,maior[MAXN],valor[MAXN];

static void dfs(int v){

	dfs_num[v] = dfsCount % MOD;
	dfsCount++;

	for(int u : grafo[v]){
		if(dfs_num[u] != -1) continue;
		nivel[u] = nivel[v] + 1;
		dfs(u);
		maior[v] = max(maior[v],maior[u]);
	}

}

static bool compara(int a,int b){
	return valor[a] < valor[b];
}

void Joi(int N, int M, int A[], int B[], long long X, int T){
	
	memset(dfs_num,-1,sizeof(dfs_num));
	dfsCount = 0;
	for(int i = 0;i<N;i++) grafo[i].clear();
	digitos.clear();

	for(int i = 0;i<MOD;i++){
		if((1LL << i) & X)	digitos.push_back(1);
		else digitos.push_back(0);
	}

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

	knuth_b gen2(1000000007);
	for(int i = 0;i<N;i++) valor[i] = gen2();

	for(int i = 0;i<N;i++) sort(grafo[i].begin(),grafo[i].end(),compara);

	dfs(0);

	if(maior[0] + 1 < MOD){
		for(int i = 0; i < N; i++){	
			MessageBoard(i, digitos[dfs_num[i]]);
		}
	}
	else{
		for(int i = 0;i<N;i++) MessageBoard(i, digitos[nivel[i] % MOD] );
	}

}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10011;
const int MOD = 60;

static deque<int> grafo[MAXN],tree[MAXN];
static int digitos[MOD],freq[MOD],distintos,processado[MAXN],dfsCount,dfs_num[MAXN],qual_digito[MAXN],pai[MAXN],nivel[MAXN],maior[MAXN],valor[MAXN];

static void add_number(int x){
	if(freq[x] == 0) distintos++;
	freq[x]++;
}

static void add_vertex(int v){
	digitos[dfs_num[v]] = qual_digito[v];
	add_number(dfs_num[v]);
}

static void greedy_add(int v){
	int qual = nivel[v] % MOD;
	digitos[qual] = qual_digito[v];
	add_number(qual);
}

static void dfs(int v){

	dfs_num[v] = dfsCount % MOD;
	dfsCount++;

	for(int u : grafo[v]){
		if(dfs_num[u] != -1) continue;
		pai[u] = v;
		nivel[u] = nivel[v] + 1;
		tree[v].push_back(u);
		dfs(u);
		maior[v] = max(maior[v],maior[u]);
	}

}

static void find_ans(int v,int st){

	processado[v] = 1;
	add_vertex(v);
	if(distintos == MOD) return;

	deque<int> temp;

	while(st != -1 && tree[v].front() != st){
		temp.push_front(tree[v].front());
		tree[v].pop_front();
	}

	for(int u : temp) tree[v].push_back(u);
	temp.clear();

	for(int u : tree[v]){
		if(distintos == MOD) return;
		if(processado[u]) continue;
		int davez = Move(u);
		qual_digito[u] = davez;
		find_ans(u,-1);
		if(distintos == MOD) return;
		Move(v);
	}

	if(distintos != MOD){
		int davez = Move(pai[v]);
		qual_digito[pai[v]] = davez;
		find_ans(pai[v],v);
	}

}

static void greedy(int v){

	greedy_add(v);
	while(v != 0 && distintos != MOD){
		int u = pai[v];
		qual_digito[u] = Move(u);
		greedy_add(u);
		v = u;
	}

	if(distintos == MOD) return;

	while(distintos != MOD){
		int mx = -1,alvo = -1;
		for(int u : tree[v]){
			if(maior[u] > mx){
				mx = maior[u];
				alvo = u;
			}
		}
		qual_digito[alvo] = Move(alvo);
		greedy_add(alvo);
		v = alvo;
	}

}

static bool compara(int a,int b){
	return valor[a] < valor[b];
}

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

	memset(dfs_num,-1,sizeof(dfs_num));
	memset(processado,0,sizeof(processado));
	memset(freq,0,sizeof(freq));
	dfsCount = 0;
	distintos = 0;
	for(int i = 0;i<N;i++) grafo[i].clear();
	for(int i = 0;i<N;i++) tree[i].clear();

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

	knuth_b gen1(1000000007);
	for(int i = 0;i<N;i++) valor[i] = gen1();

	for(int i = 0;i<N;i++) sort(grafo[i].begin(),grafo[i].end(),compara);

	dfs(0);

	qual_digito[P] = V;

	if(maior[0] + 1 < MOD) find_ans(P,-1);
	else greedy(P);

	long long ans = 0;
	for(int i = 0;i<MOD;i++) if(digitos[i]) ans += (1LL << i);

	return ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14688 KB Output is correct
2 Correct 17 ms 28176 KB Output is correct
3 Correct 18 ms 28548 KB Output is correct
4 Correct 16 ms 28856 KB Output is correct
5 Correct 17 ms 28856 KB Output is correct
6 Correct 17 ms 28856 KB Output is correct
7 Correct 17 ms 28856 KB Output is correct
8 Correct 19 ms 28856 KB Output is correct
9 Correct 17 ms 28856 KB Output is correct
10 Correct 17 ms 28856 KB Output is correct
11 Correct 23 ms 28880 KB Output is correct
12 Correct 16 ms 28904 KB Output is correct
13 Correct 20 ms 28904 KB Output is correct
14 Correct 18 ms 28904 KB Output is correct
15 Correct 20 ms 28904 KB Output is correct
16 Correct 22 ms 28904 KB Output is correct
17 Correct 17 ms 28904 KB Output is correct
18 Correct 19 ms 28904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 30280 KB Output is correct
2 Correct 57 ms 31944 KB Output is correct
3 Correct 63 ms 32408 KB Output is correct
4 Correct 50 ms 32584 KB Output is correct
5 Correct 41 ms 32584 KB Output is correct
6 Correct 46 ms 32584 KB Output is correct
7 Correct 40 ms 32584 KB Output is correct
8 Correct 43 ms 32596 KB Output is correct
9 Correct 43 ms 32704 KB Output is correct
10 Correct 36 ms 32800 KB Output is correct
11 Correct 37 ms 32800 KB Output is correct
12 Correct 39 ms 32800 KB Output is correct
13 Correct 37 ms 32816 KB Output is correct
14 Correct 41 ms 33024 KB Output is correct
15 Correct 46 ms 33280 KB Output is correct
16 Correct 38 ms 33364 KB Output is correct
17 Correct 35 ms 33560 KB Output is correct
18 Correct 41 ms 33824 KB Output is correct
19 Correct 42 ms 34016 KB Output is correct
20 Correct 40 ms 34572 KB Output is correct
21 Correct 40 ms 35068 KB Output is correct
22 Correct 39 ms 35208 KB Output is correct
23 Correct 37 ms 35436 KB Output is correct
24 Correct 43 ms 35568 KB Output is correct
25 Correct 45 ms 35596 KB Output is correct
26 Correct 41 ms 35860 KB Output is correct
27 Correct 54 ms 36180 KB Output is correct
28 Correct 41 ms 36348 KB Output is correct
29 Correct 48 ms 36432 KB Output is correct
30 Correct 47 ms 36488 KB Output is correct
31 Correct 19 ms 36544 KB Output is correct
32 Correct 16 ms 36544 KB Output is correct
33 Correct 17 ms 36544 KB Output is correct
34 Correct 20 ms 36544 KB Output is correct
35 Correct 18 ms 36544 KB Output is correct
36 Correct 17 ms 36544 KB Output is correct
37 Correct 19 ms 36544 KB Output is correct
38 Correct 18 ms 36544 KB Output is correct
39 Correct 17 ms 36544 KB Output is correct
40 Correct 19 ms 36544 KB Output is correct
41 Correct 20 ms 36544 KB Output is correct
42 Correct 20 ms 36544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 36544 KB Output is correct
2 Correct 18 ms 36544 KB Output is correct
3 Correct 20 ms 36544 KB Output is correct
4 Correct 27 ms 36544 KB Output is correct
5 Correct 23 ms 36544 KB Output is correct
6 Correct 20 ms 36544 KB Output is correct
7 Correct 22 ms 36544 KB Output is correct
8 Correct 24 ms 36544 KB Output is correct
9 Correct 39 ms 37428 KB Output is correct
10 Correct 38 ms 38408 KB Output is correct
11 Correct 44 ms 38600 KB Output is correct
12 Correct 18 ms 38696 KB Output is correct
13 Correct 18 ms 38696 KB Output is correct
14 Correct 19 ms 38696 KB Output is correct
15 Correct 20 ms 38696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 38780 KB Output is correct
2 Correct 53 ms 39056 KB Output is correct
3 Correct 72 ms 39440 KB Output is correct
4 Correct 35 ms 39632 KB Output is correct
5 Correct 41 ms 39692 KB Output is correct
6 Partially correct 50 ms 39752 KB Partially correct
7 Correct 41 ms 39752 KB Output is correct
8 Correct 41 ms 39752 KB Output is correct
9 Correct 48 ms 39832 KB Output is correct
10 Correct 53 ms 39912 KB Output is correct
11 Correct 37 ms 39940 KB Output is correct
12 Correct 41 ms 39968 KB Output is correct
13 Correct 38 ms 39968 KB Output is correct
14 Correct 35 ms 39968 KB Output is correct
15 Correct 38 ms 39968 KB Output is correct
16 Partially correct 38 ms 39968 KB Partially correct
17 Correct 40 ms 39968 KB Output is correct
18 Correct 39 ms 39968 KB Output is correct
19 Correct 36 ms 39968 KB Output is correct
20 Correct 34 ms 40328 KB Output is correct
21 Correct 37 ms 40688 KB Output is correct
22 Correct 38 ms 40688 KB Output is correct
23 Correct 36 ms 40688 KB Output is correct
24 Correct 38 ms 40688 KB Output is correct
25 Correct 43 ms 40688 KB Output is correct
26 Correct 38 ms 40688 KB Output is correct
27 Correct 43 ms 40688 KB Output is correct
28 Correct 38 ms 40688 KB Output is correct
29 Correct 33 ms 40688 KB Output is correct
30 Correct 38 ms 40688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 41024 KB Output is correct
2 Correct 49 ms 41400 KB Output is correct
3 Correct 50 ms 41588 KB Output is correct
4 Correct 35 ms 41736 KB Output is correct
5 Correct 45 ms 41736 KB Output is correct
6 Correct 39 ms 41736 KB Output is correct
7 Correct 40 ms 41736 KB Output is correct
8 Correct 39 ms 41736 KB Output is correct
9 Correct 41 ms 41736 KB Output is correct
10 Correct 43 ms 41736 KB Output is correct
11 Correct 43 ms 41736 KB Output is correct
12 Correct 40 ms 41736 KB Output is correct
13 Correct 39 ms 41736 KB Output is correct
14 Correct 42 ms 41768 KB Output is correct
15 Correct 49 ms 42000 KB Output is correct
16 Correct 47 ms 42292 KB Output is correct
17 Correct 43 ms 42400 KB Output is correct
18 Correct 41 ms 42512 KB Output is correct
19 Correct 39 ms 42704 KB Output is correct
20 Correct 33 ms 43264 KB Output is correct
21 Correct 32 ms 43852 KB Output is correct
22 Correct 35 ms 43976 KB Output is correct
23 Correct 38 ms 43980 KB Output is correct
24 Correct 35 ms 44164 KB Output is correct
25 Correct 35 ms 44408 KB Output is correct
26 Correct 37 ms 44676 KB Output is correct
27 Correct 37 ms 44996 KB Output is correct
28 Correct 39 ms 45208 KB Output is correct
29 Correct 34 ms 45328 KB Output is correct
30 Correct 39 ms 45440 KB Output is correct
31 Correct 18 ms 45528 KB Output is correct
32 Correct 18 ms 45528 KB Output is correct
33 Correct 19 ms 45528 KB Output is correct
34 Incorrect 16 ms 45528 KB Output isn't correct
35 Halted 0 ms 0 KB -