# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
151699 | gs14004 | 로카히아 유적 (FXCUP4_lokahia) | C++17 | 3 ms | 716 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "lokahia.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using group = pair<vector<int>, vector<int>>;
int lca(int x, int y){
return x == y ? x : CollectRelics(x, y);
}
int FindBase(int N){
vector<group> grp;
group g;
for(int i=0; i<N; i++){
if(sz(g.first) == 0){
g.first.push_back(i);
continue;
}
int query = lca(g.first[0], i);
if(query == -1){
g.second.push_back(i);
}
else{
g.first.push_back(i);
g.first[0] = query;
}
if(sz(g.first) == sz(g.second)){
grp.push_back(g);
group h; g = h;
}
}
if(sz(g.first)) grp.push_back(g);
int who = grp.back().first[0];
int cnt = 0;
for(auto &i : grp){
int comp = lca(i.first[0], who);
if(comp != -1){
who = comp;
cnt += sz(i.first);
}
else{
for(auto &j : i.second){
int L = lca(who, j);
if(L != -1) who = L, cnt++;
}
}
}
if(cnt >= N / 2 + 1) return who;
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |