답안 #247329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247329 2020-07-11T08:47:17 Z dwsc 로카히아 유적 (FXCUP4_lokahia) C++17
100 / 100
9 ms 844 KB
#include <bits/stdc++.h>
#include "lokahia.h"
using namespace std;
int p[210];
int visit[210][210];
int num[210];
int findset(int i){
    return p[i]==i?p[i]:p[i]=findset(p[i]);
}
int FindBase(int N){
    srand(3082);
	int counter = 0;
	for (int i = 0; i < N; i++) p[i] = i;
	int fail = 0;
	while (counter < 100){
        int a = rand()%N,b = rand()%N;
        if (fail > 100000) break;
        fail++;
        if (a == b) continue;
        if (visit[findset(a)][findset(b)]) continue;
        if (findset(a) == findset(b)) continue;
        fail = 0;
        counter++;
        int x = findset(a),y = findset(b);
        visit[x][y] = visit[y][x] = 1;
        int temp = CollectRelics(a,b);
        if (temp != -1) {
            for (int i = 0; i < N; i++){
                visit[temp][i] = visit[i][temp] = max(visit[temp][i],max(visit[x][i],visit[y][i]));
            }
            p[x] = temp;
            p[y] = temp;
        }
	}
    for (int i = 0; i < N; i++){
        num[findset(i)]++;
    }
    int maxi = 0,cur = -1;
    for (int i = 0; i < N; i++){
        if (num[i] >= maxi){
            maxi = num[i];
            cur = i;
        }
    }
    int tot = 0;
    for (int i = 0; i < N; i++){
        if (findset(i)== cur) tot++;
        else tot += CollectRelics(i,cur)!=-1;
    }
    if (tot > N/2) return cur;
    return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Correct : C = 290
2 Correct 5 ms 672 KB Correct : C = 218
3 Correct 6 ms 768 KB Correct : C = 261
4 Correct 5 ms 640 KB Correct : C = 194
5 Correct 5 ms 768 KB Correct : C = 251
6 Correct 6 ms 768 KB Correct : C = 254
7 Correct 9 ms 488 KB Correct : C = 3
8 Correct 6 ms 768 KB Correct : C = 256
9 Correct 5 ms 640 KB Correct : C = 187
10 Correct 5 ms 768 KB Correct : C = 298
11 Correct 7 ms 768 KB Correct : C = 257
12 Correct 7 ms 512 KB Correct : C = 0
13 Correct 5 ms 640 KB Correct : C = 175
14 Correct 6 ms 768 KB Correct : C = 252
15 Correct 8 ms 640 KB Correct : C = 93
16 Correct 5 ms 640 KB Correct : C = 184
17 Correct 6 ms 768 KB Correct : C = 150
18 Correct 5 ms 768 KB Correct : C = 299
19 Correct 5 ms 640 KB Correct : C = 186
20 Correct 5 ms 640 KB Correct : C = 219
21 Correct 5 ms 768 KB Correct : C = 247
22 Correct 5 ms 800 KB Correct : C = 262
23 Correct 6 ms 844 KB Correct : C = 264
24 Correct 6 ms 768 KB Correct : C = 158
25 Correct 9 ms 640 KB Correct : C = 88
26 Correct 5 ms 640 KB Correct : C = 174
27 Correct 5 ms 768 KB Correct : C = 291