#include <bits/stdc++.h>
#include "lokahia.h"
using namespace std;
#define ll long long
#define fi first
#define se second
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
mt19937 rng (chrono::system_clock::now().time_since_epoch().count());
const int trial=20; //test different startings
const int samples=15; //test different random places
vector<int> shuf(vector<int> v){
rep(x,0,sz(v)){
swap(v[x],v[rng()%(x+1)]);
}
return v;
}
int FindBase(int n){
if (n==1) return 1;
int best=-1;
int root;
vector<int> v;
rep(x,0,n) v.push_back(x);
shuf(v);
rep(x,0,min(trial,sz(v))){
int node=v[x];
int curr=0;
rep(zzz,0,samples){
int temp;
do{
temp=rng()%n;
} while (temp==node);
//cout<<"debug: "<<node<<" "<<temp<<endl;
if (CollectRelics(node,temp)!=-1) curr++;
}
if (curr>best){
best=curr;
root=node;
}
}
int ans=-1;
int cnt=1;
rep(x,0,n) if (x!=root){
int temp=CollectRelics(root,x);
if (temp!=-1) cnt++,ans=max(ans,temp);
}
//cout<<ans<<" "<<cnt<<endl;
if (cnt>n/2) return ans;
else return -1;
}
Compilation message
lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:60:13: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
rep(x,0,n) if (x!=root){
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
640 KB |
Partially correct : C = 499 |
2 |
Incorrect |
5 ms |
512 KB |
Wrong |
3 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 418 |
4 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
5 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
6 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 419 |
7 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |
8 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 418 |
9 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 419 |
10 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
11 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
12 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 418 |
13 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 419 |
14 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |
15 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
16 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 419 |
17 |
Incorrect |
5 ms |
640 KB |
Wrong |
18 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 419 |
19 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |
20 |
Correct |
4 ms |
512 KB |
Correct : C = 79 |
21 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 418 |
22 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |
23 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
24 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 418 |
25 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |
26 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 499 |
27 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 498 |