# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
247360 | dantoh000 | 로카히아 유적 (FXCUP4_lokahia) | C++17 | 39 ms | 888 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |