# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321119 | seedkin | Lokahian Relics (FXCUP4_lokahia) | C++17 | 2 ms | 620 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "lokahia.h"
#include <stdio.h>
int root[205]; // who is root?
int select[205]; // able to get mana?
int findRoot(int r, int leaf) {
if(r == leaf) return select[r];
int temp = root[leaf];
select[r] += select[leaf];
root[leaf] = r;
select[leaf] = 0;
return temp == -1 ? select[r]: findRoot(r, temp);
}
int getRoot(int n) {
int r = root[n];
if(r == -1) return n;
findRoot(r, n);
root[n] = getRoot(r);
return root[n];
}
int FindBase(int N){
if(N==1) return 0;
int target = N / 2;
int boss[205];
int bossNum = 0;
for(int i =0; i < N; i++) {
root[i] = -1;
select[i] = 1;
boss[i] = 0;
}
int s= 0;
for(int i =0; i< N; i++) {
if( s == 0) {
boss[bossNum++] = i;
s = 1;
continue;
}
if(getRoot(boss[bossNum-1]) == getRoot(i)) {
s++;
continue;
}
int r = CollectRelics(getRoot(boss[bossNum-1]), getRoot(i));
if( r == -1) {
s--;
if(s == 0) {
if(i == N-1) return -1;
}
continue;
}
int num = findRoot(getRoot(r), getRoot(boss[bossNum-1]));
num = findRoot(getRoot(r),getRoot(i));
if(num > target) return getRoot(r);
s++;
}
int c = boss[bossNum-1];
for(int i =0; i < bossNum-1; i++) {
int a = boss[i];
if(getRoot(c) == getRoot(a)) continue;
int r = CollectRelics(getRoot(c), getRoot(a));
if(r == -1) {
int b = boss[i+1];
for(int j = a+1; j < b; j++) {
if(getRoot(c) == getRoot(j)) continue;
if(getRoot(j) != j) continue;
r = CollectRelics(getRoot(c), getRoot(j));
if(r == -1) continue;
int num = findRoot(getRoot(r), getRoot(c));
num = findRoot(getRoot(r), getRoot(j));
if(num > target) return getRoot(r);
}
continue;
}
int num = findRoot(getRoot(r), getRoot(c));
num = findRoot(getRoot(r), getRoot(a));
if(num > target) return getRoot(r);
}
if(select[getRoot(c)] > target ) return getRoot(c);
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |