Submission #320580

# Submission time Handle Problem Language Result Execution time Memory
320580 2020-11-09T07:02:55 Z seedkin Lokahian Relics (FXCUP4_lokahia) C++17
0 / 100
2 ms 768 KB
#include "lokahia.h"
#include <stdio.h>

int root[205]; // who is root?
int select[205]; // able to get mana?
int isRoot[205]; // 1== root 0 == no
int target;

int findRoot(int r, int leaf) {
	if(r == leaf) return select[r];

	int temp = root[leaf];
	select[r] += select[leaf];
	root[leaf] = r;
	select[leaf] = 0;
	isRoot[leaf] = 0;
	// isRoot[r] = 1;

	return temp == -1 ? select[r]: findRoot(r, temp);
}

int getSelect(int n, int d) {
	if(root[n] != -1) return getSelect(root[n], d);
	isRoot[n] = d;
	return select[n];
}

int FindBase(int N){
	// printf("%d\n", CollectRelics(0, 1));
	target = N / 2;
	int except = 0;
	

	for(int i =0; i < N; i++) {
		root[i] = -1;
		select[i] = 1;
		isRoot[i] = 1;
	}

	// if(N % 2) isRoot[N-1] = 1;

	// for(int i =0; i+1 < N; i+=2) {
	// 	int r = CollectRelics(i, i+1);
	// 	if( r == -1) {
	// 		isRoot[i] = 1;
	// 		isRoot[i+1] = 1;
	// 		continue;
	// 	}
	// 	int num = findRoot(r, i);		
	// 	num = findRoot(r, i+1);
	// 	if(num >= target) return r;		
	// }

	for(int i =0; i < N; i++) {
		if(isRoot[i] ==0) continue;
		int e = 0;
		for(int j = i+1; j< N; j++) {
			if(isRoot[j] == 0) continue;
			if(N - e < target) break;
			int r = CollectRelics(i, j);
			if( r == -1) {
				e += getSelect(j, 1);
				continue;
			}
			int num = findRoot(r, i);		
			num = findRoot(r, j);
			if(num >= target) return r;
		}
		except += getSelect(i, 0);
		if(N - except < target) return -1;
	}

	// for(int i =0; i< N; i++) {
	// 	printf("node: %d select: %d\n", i, select[i]);
	// }
	return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 620 KB Wrong
2 Incorrect 1 ms 620 KB Wrong
3 Incorrect 1 ms 512 KB Wrong
4 Incorrect 0 ms 492 KB Wrong
5 Incorrect 1 ms 620 KB Wrong
6 Correct 1 ms 620 KB Correct : C = 117
7 Correct 1 ms 640 KB Correct : C = 101
8 Partially correct 0 ms 620 KB Partially correct : C = 599
9 Correct 1 ms 620 KB Correct : C = 168
10 Correct 1 ms 640 KB Correct : C = 169
11 Incorrect 1 ms 620 KB Wrong
12 Correct 1 ms 620 KB Correct : C = 296
13 Correct 1 ms 620 KB Correct : C = 197
14 Correct 1 ms 492 KB Correct : C = 1
15 Correct 1 ms 620 KB Correct : C = 118
16 Correct 1 ms 620 KB Correct : C = 59
17 Incorrect 1 ms 620 KB Wrong
18 Partially correct 1 ms 620 KB Partially correct : C = 399
19 Incorrect 1 ms 620 KB Wrong
20 Incorrect 1 ms 620 KB Wrong
21 Partially correct 2 ms 620 KB Partially correct : C = 598
22 Incorrect 1 ms 768 KB Wrong
23 Correct 2 ms 620 KB Correct : C = 99
24 Correct 1 ms 492 KB Correct : C = 58
25 Correct 1 ms 628 KB Correct : C = 98
26 Correct 1 ms 620 KB Correct : C = 116
27 Correct 1 ms 620 KB Correct : C = 197