답안 #247360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247360 2020-07-11T08:58:09 Z dantoh000 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
39 ms 888 KB
#include <bits/stdc++.h>
using namespace std;
#include "lokahia.h"
int n;
int Q[205][205];
const int LIM = 400;
int tq = 0;
int p[205];
int find(int x){
    return p[x] == x ? x:  p[x] = find(p[x]);
}
int query(int i, int j){
    i = find(i), j = find(j);
    if (i == j) return Q[i][i] = i;
    else if (tq >= LIM) return -1;
    else{
        for (int x = 0; x < n; x++){
            for (int y = 0; y < n; y++){
                if (find(x) == i && find(y) == j && Q[x][y] != -2){
                    return Q[i][j] = Q[j][i] = Q[x][y];
                }
            }
        }
        tq++;
        return Q[i][j] = Q[j][i] = CollectRelics(i,j);
    }
}
int FindBase(int N){
    n = N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) Q[i][j] = -2;
        p[i] = i;
    }

    vector<int> good;
    for (int i = 0; i < N; i++) good.push_back(i);
    while (good.size() && tq <= LIM){
        int cur = good[0];
        srand(time(NULL));
        random_shuffle(good.begin(),good.end());
        for (auto x : good){
            if (cur == x) continue;
            int q = query(cur,x);
            if (q != -1 && q > cur) {
                p[cur] = p[x] = q;
                cur = q;
            }
        }
        int ct = 0;
        vector<int> bad;
        for (auto x : good){
            if (x == cur || query(x,cur) != -1) {
                p[x] = cur;
                ct++;
            }
            else bad.push_back(x);
            if (ct > N/2) break;
        }
        if (ct > N/2) return cur;
        good.clear();
        for (auto x : bad){
            good.push_back(x);
        }
        bad.clear();
    }
    return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 640 KB Correct : C = 117
2 Partially correct 16 ms 640 KB Partially correct : C = 400
3 Correct 20 ms 768 KB Correct : C = 197
4 Correct 8 ms 640 KB Correct : C = 117
5 Partially correct 38 ms 768 KB Partially correct : C = 400
6 Correct 5 ms 512 KB Correct : C = 0
7 Partially correct 39 ms 768 KB Partially correct : C = 400
8 Partially correct 36 ms 768 KB Partially correct : C = 400
9 Partially correct 17 ms 640 KB Partially correct : C = 400
10 Partially correct 34 ms 768 KB Partially correct : C = 400
11 Correct 19 ms 768 KB Correct : C = 197
12 Partially correct 37 ms 768 KB Partially correct : C = 400
13 Partially correct 37 ms 768 KB Partially correct : C = 400
14 Correct 21 ms 768 KB Correct : C = 198
15 Correct 21 ms 768 KB Correct : C = 198
16 Correct 9 ms 640 KB Correct : C = 118
17 Correct 11 ms 640 KB Correct : C = 117
18 Partially correct 27 ms 640 KB Partially correct : C = 371
19 Correct 8 ms 640 KB Correct : C = 118
20 Incorrect 38 ms 768 KB Wrong
21 Correct 35 ms 888 KB Correct : C = 297
22 Incorrect 34 ms 768 KB Wrong
23 Partially correct 17 ms 752 KB Partially correct : C = 400
24 Correct 5 ms 512 KB Correct : C = 3
25 Correct 18 ms 768 KB Correct : C = 198
26 Correct 20 ms 768 KB Correct : C = 198
27 Correct 8 ms 640 KB Correct : C = 118