#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=10; //test different startings
const int samples=30; //test different random places
int memo[205][205];
int get(int i,int j){
if (memo[i][j]!=-1) return memo[i][j];
return memo[i][j]=memo[j][i]=CollectRelics(i,j);
}
vector<int> shuf(vector<int> v){
rep(x,0,sz(v)){
swap(v[x],v[rng()%(x+1)]);
}
return v;
}
int FindBase(int n){
memset(memo,-1,sizeof(memo));
if (n<=20){ //maybe
rep(root,0,n){
int cnt=1;
int ans=-1;
rep(x,0,n) if (x!=root){
int temp=get(root,x);
if (temp!=-1) cnt++,ans=max(ans,temp);
}
if (cnt>n/2) return ans;
}
return -1;
}
int best=-1;
int root;
vector<int> v;
rep(x,0,n) v.push_back(x);
shuf(v);
rep(x,0,trial){
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 (get(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=get(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:84:13: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
rep(x,0,n) if (x!=root){
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 476 |
2 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 472 |
3 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 498 |
4 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 486 |
5 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 418 |
6 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 357 |
7 |
Partially correct |
5 ms |
896 KB |
Partially correct : C = 451 |
8 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 479 |
9 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 471 |
10 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 393 |
11 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 419 |
12 |
Correct |
5 ms |
640 KB |
Correct : C = 4 |
13 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 392 |
14 |
Partially correct |
5 ms |
896 KB |
Partially correct : C = 469 |
15 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 499 |
16 |
Incorrect |
5 ms |
640 KB |
Wrong |
17 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 469 |
18 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 451 |
19 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 467 |
20 |
Partially correct |
5 ms |
896 KB |
Partially correct : C = 467 |
21 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 483 |
22 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 471 |
23 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 379 |
24 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 351 |
25 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 394 |
26 |
Partially correct |
5 ms |
896 KB |
Partially correct : C = 376 |
27 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 392 |