답안 #150813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150813 2019-09-01T08:57:27 Z お前はもう死んでいる(#3784, kuroni, nvmdava, tfg) 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
7 ms 768 KB
#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 205;

int dsu[N];

int trace(int u)
{
	return dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]);
}

void connect(int u, int v)
{
	if ((u = trace(u)) == (v = trace(v)))
		return;
	if (dsu[u] > dsu[v])
		swap(u, v);
	int tmp = dsu[v];
	dsu[u] += dsu[v];
	dsu[v] = u;
}

int FindBase(int N){
    vector<vector<int> > s, t, de;
    vector<int> la;
    for(int i = 0; i < N; i++)
	{
		dsu[i] = -1;
		s.push_back({i});
	}
 
    while(s.size() > 1){
        for(int i = 1; i < s.size(); i += 2){
            if(trace(s[i - 1][0]) == trace(s[i][0]) || CollectRelics(s[i - 1][0], s[i][0]) != -1){
				connect(s[i - 1][0], s[i - 1][1]);
                for(int& x : s[i - 1])
                    s[i].push_back(x);
                t.push_back(s[i]);
            } else {
                de.push_back(s[i - 1]);
                de.push_back(s[i]);
            }
        }

        if(s.size() & 1){
            de.push_back(s.back());
            la = s.back();
        }

        swap(s, t);
        t.clear();
    }
 
    int sz = 0;
    
    if(s.empty()) s.push_back(la);
    else sz = s[0].size();
    if(s[0].empty()) return -1;

    int res = 0;

    for(int i = 1; i < s[0].size(); i++){
        res = max(res, CollectRelics(s[0][i], s[0][0]));
    }

    for(auto& x : de){
        int rrr = CollectRelics(x[0], s[0][0]);
        if(rrr != -1){
            res = max(res, rrr);
            for(int i = 1; i < x.size(); i++){
                rrr = CollectRelics(x[i], s[0][0]);
                res = max(res, rrr);
            }
            sz += x.size();
        }
    }
    if(sz > N / 2) return res;
    return -1;
}

Compilation message

lokahia.cpp: In function 'void connect(int, int)':
lokahia.cpp:20:6: warning: unused variable 'tmp' [-Wunused-variable]
  int tmp = dsu[v];
      ^~~
lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:35:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 1; i < s.size(); i += 2){
                        ~~^~~~~~~~~~
lokahia.cpp:64:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < s[0].size(); i++){
                    ~~^~~~~~~~~~~~~
lokahia.cpp:72:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 1; i < x.size(); i++){
                            ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 640 KB Wrong
2 Partially correct 6 ms 640 KB Partially correct : C = 321
3 Incorrect 6 ms 640 KB Wrong
4 Correct 7 ms 640 KB Correct : C = 131
5 Partially correct 6 ms 640 KB Partially correct : C = 316
6 Incorrect 6 ms 640 KB Wrong
7 Partially correct 6 ms 640 KB Partially correct : C = 314
8 Correct 5 ms 512 KB Correct : C = 7
9 Partially correct 6 ms 768 KB Partially correct : C = 392
10 Partially correct 7 ms 640 KB Partially correct : C = 328
11 Partially correct 6 ms 640 KB Partially correct : C = 318
12 Incorrect 6 ms 640 KB Wrong
13 Correct 6 ms 688 KB Correct : C = 105
14 Correct 6 ms 512 KB Correct : C = 0
15 Correct 6 ms 512 KB Correct : C = 194
16 Correct 6 ms 640 KB Correct : C = 188
17 Correct 6 ms 640 KB Correct : C = 235
18 Correct 5 ms 640 KB Correct : C = 231
19 Partially correct 6 ms 640 KB Partially correct : C = 331
20 Correct 6 ms 560 KB Correct : C = 188
21 Incorrect 6 ms 640 KB Wrong
22 Correct 6 ms 640 KB Correct : C = 190
23 Incorrect 6 ms 512 KB Wrong
24 Correct 6 ms 640 KB Correct : C = 100
25 Correct 6 ms 640 KB Correct : C = 189
26 Partially correct 6 ms 640 KB Partially correct : C = 396
27 Correct 6 ms 640 KB Correct : C = 60