답안 #249021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249021 2020-07-14T06:23:24 Z SomeoneUnknown 로카히아 유적 (FXCUP4_lokahia) C++17
100 / 100
1 ms 640 KB
#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
vector<bool> matched;
int getpar(int x){
    //printf("getpar %d\n", x);
    if(par[x] != x){
        par[x] = getpar(par[x]);
    }
    return par[x];
}
int FindBase(int N){
    //int par[N];
    int disjointtotal = 0;
    for(int i = 0; i < N; ++i){
        par.push_back(i);
        matched.push_back(false);
    }
    int frst;
    while(true){
        frst = -1;
        bool fin = true;
        for(int i = 0; i < N; ++i){
            if(matched[i]) continue;
            if(frst == -1){
                frst = i;
                continue;
            }
            if(getpar(frst) != getpar(i)){
                int res = CollectRelics(getpar(frst), getpar(i));
                if(res == -1){
                    ++disjointtotal;
                    if(disjointtotal * 2 >= N) return -1;
                    matched[i] = matched[frst] = true;
                }else{
                    res = getpar(res);
                    par[getpar(frst)] = res;
                    par[getpar(i)] = res;
                }
                fin = false;
                break;
            }
        }
        if(fin) break;
    }
    int llone = frst; //yes, this is copypasted.
    for(int i = 0; i < N; ++i){
        if(i == llone || par[i] != i) continue;
        int res = CollectRelics(i, llone);
        if(res == -1) continue;
        res = getpar(res);
        par[llone] = res;
        par[i] = res;
        llone = res;
    }
    int llonesize = 0;
    for(int i = 0; i < N; ++i){
        if(getpar(i) == llone) llonesize++;
    }
    if(llonesize * 2 > N) return llone;
    //CollectRelics()
	return -1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Correct : C = 198
2 Correct 1 ms 512 KB Correct : C = 174
3 Correct 1 ms 640 KB Correct : C = 111
4 Correct 1 ms 640 KB Correct : C = 293
5 Correct 1 ms 512 KB Correct : C = 172
6 Correct 1 ms 512 KB Correct : C = 60
7 Correct 1 ms 640 KB Correct : C = 291
8 Correct 1 ms 640 KB Correct : C = 297
9 Correct 1 ms 640 KB Correct : C = 189
10 Correct 1 ms 640 KB Correct : C = 281
11 Correct 1 ms 640 KB Correct : C = 294
12 Correct 1 ms 512 KB Correct : C = 171
13 Correct 1 ms 512 KB Correct : C = 174
14 Correct 1 ms 512 KB Correct : C = 118
15 Correct 0 ms 512 KB Correct : C = 5
16 Correct 1 ms 640 KB Correct : C = 100
17 Correct 0 ms 512 KB Correct : C = 0
18 Correct 1 ms 640 KB Correct : C = 283
19 Correct 1 ms 512 KB Correct : C = 170
20 Correct 1 ms 512 KB Correct : C = 119
21 Correct 1 ms 640 KB Correct : C = 294
22 Correct 1 ms 640 KB Correct : C = 289
23 Correct 1 ms 640 KB Correct : C = 199
24 Correct 1 ms 512 KB Correct : C = 176
25 Correct 1 ms 632 KB Correct : C = 282
26 Correct 1 ms 512 KB Correct : C = 177
27 Correct 1 ms 640 KB Correct : C = 288