#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=15; //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;
}
bool vis[205];
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;
}
vector<int> v;
rep(x,0,n) v.push_back(x);
v=shuf(v);
vector<int> cand;
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>=samples/2){
cand.push_back(node);
}
}
for (auto &it:cand){
if (vis[it]) continue;
vis[it]=true;
int cnt=1;
int ans=-1;
rep(x,0,n) if (!vis[x]){
int temp=get(it,x);
if (temp!=-1){
ans=max(ans,temp);
cnt++;
vis[x]=true;
}
}
//cout<<it<<" "<<cnt<<" "<<ans<<endl;
if (cnt>n/2) return ans;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Correct : C = 260 |
2 |
Correct |
5 ms |
768 KB |
Correct : C = 150 |
3 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 339 |
4 |
Correct |
5 ms |
768 KB |
Correct : C = 150 |
5 |
Correct |
6 ms |
768 KB |
Correct : C = 257 |
6 |
Correct |
5 ms |
768 KB |
Correct : C = 255 |
7 |
Correct |
5 ms |
768 KB |
Correct : C = 150 |
8 |
Partially correct |
6 ms |
896 KB |
Partially correct : C = 338 |
9 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 336 |
10 |
Partially correct |
5 ms |
896 KB |
Partially correct : C = 340 |
11 |
Correct |
5 ms |
768 KB |
Correct : C = 258 |
12 |
Partially correct |
6 ms |
896 KB |
Partially correct : C = 333 |
13 |
Correct |
5 ms |
768 KB |
Correct : C = 150 |
14 |
Correct |
6 ms |
768 KB |
Correct : C = 251 |
15 |
Partially correct |
6 ms |
768 KB |
Partially correct : C = 327 |
16 |
Correct |
5 ms |
768 KB |
Correct : C = 241 |
17 |
Partially correct |
6 ms |
768 KB |
Partially correct : C = 324 |
18 |
Correct |
5 ms |
768 KB |
Correct : C = 259 |
19 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 338 |
20 |
Correct |
5 ms |
768 KB |
Correct : C = 150 |
21 |
Partially correct |
6 ms |
768 KB |
Partially correct : C = 339 |
22 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 426 |
23 |
Correct |
5 ms |
640 KB |
Correct : C = 4 |
24 |
Incorrect |
5 ms |
640 KB |
Wrong |
25 |
Partially correct |
5 ms |
768 KB |
Partially correct : C = 337 |
26 |
Correct |
5 ms |
768 KB |
Correct : C = 149 |
27 |
Correct |
5 ms |
768 KB |
Correct : C = 245 |