답안 #320806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320806 2020-11-10T01:30:28 Z seedkin 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
4 ms 1004 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, c);
				num = findRoot(r, j);
				if(num > target) return r;
			}
			continue;
		}
		int num = findRoot(r, c);
		num = findRoot(r, a);
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 2 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 2 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Correct 1 ms 620 KB Correct : C = 59
6 Correct 1 ms 620 KB Correct : C = 171
7 Correct 1 ms 620 KB Correct : C = 276
8 Runtime error 2 ms 876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Incorrect 1 ms 620 KB Wrong
10 Incorrect 1 ms 620 KB Wrong
11 Correct 1 ms 620 KB Correct : C = 211
12 Runtime error 3 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Correct 1 ms 620 KB Correct : C = 99
14 Correct 1 ms 620 KB Correct : C = 126
15 Incorrect 1 ms 620 KB Wrong
16 Incorrect 1 ms 620 KB Wrong
17 Correct 1 ms 620 KB Correct : C = 81
18 Runtime error 3 ms 876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 2 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Correct 1 ms 620 KB Correct : C = 60
21 Runtime error 4 ms 1004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Correct 1 ms 620 KB Correct : C = 119
23 Correct 1 ms 620 KB Correct : C = 126
24 Correct 1 ms 620 KB Correct : C = 100
25 Correct 1 ms 620 KB Correct : C = 100
26 Correct 1 ms 620 KB Correct : C = 60
27 Correct 1 ms 492 KB Correct : C = 2