Submission #320805

# Submission time Handle Problem Language Result Execution time Memory
320805 2020-11-10T01:29:08 Z seedkin Lokahian Relics (FXCUP4_lokahia) C++17
Compilation error
0 ms 0 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;
	int boss[205];
	int bossNum = 0;
	
	for(int i =0; i < N; i++) {
		root[i] = -1;
		select[i] = 1;
		isRoot[i] = 1;
		boss[i] = 0;
	}

	for(int i =0; i< N;) {
		int s = 1;
		boss[bossNum++] = i;
		for(int j =i+1; j < N; j++) {
			int r = CollectRelics(i, j);
			if( r == -1) {
				s--;
				if(s == 0) {
					i = j+1;
					break;
				}
				continue;
			}
			int num = findRoot(r, i);
			num = findRoot(r, j);
			if(num > target) return r;
		}
	}
	
	int c = boss[bossNum-1];

	for(int i =0; i < bossNum-1; i++) {
		int a = boss[i];
		if(root[c] == root[a]) continue;
		int r = CollectRelics(c, a);
		if(r == -1) {
			int b = boss[i+1];
			for(int j = a+1; j < b; j++) {
				if(root[j] == root[c]) continue;
				if(isRoot[j] == 0) continue;
				r = CollectRelics(c, j);
				if(r == -1) continue;
				int num = findRoot(r, i);
				num = findRoot(r, j);
				if(num > target) return r;
			}
		}
		int num = findRoot(r, i);
		num = findRoot(r, j);
		if(num > target) return r;
	}	
	// for(int i =0; i < N; i++) {
	// 	if(isRoot[i] ==0) continue;
	// 	for(int j = i+1; j< N; j++) {
	// 		if(isRoot[j] == 0) continue;
	// 		int r = CollectRelics(i, j);
	// 		if( r == -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;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:80:21: error: 'j' was not declared in this scope
   80 |   num = findRoot(r, j);
      |                     ^
lokahia.cpp:31:6: warning: unused variable 'except' [-Wunused-variable]
   31 |  int except = 0;
      |      ^~~~~~