답안 #247121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247121 2020-07-11T06:18:37 Z errorgorn 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
6 ms 896 KB
#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=15; //test different startings
const int samples=6; //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){
             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Correct : C = 208
2 Correct 5 ms 768 KB Correct : C = 281
3 Incorrect 6 ms 768 KB Wrong
4 Correct 6 ms 640 KB Correct : C = 4
5 Correct 5 ms 768 KB Correct : C = 209
6 Correct 5 ms 768 KB Correct : C = 200
7 Correct 5 ms 768 KB Correct : C = 283
8 Correct 5 ms 768 KB Correct : C = 285
9 Correct 5 ms 768 KB Correct : C = 282
10 Correct 6 ms 896 KB Correct : C = 282
11 Correct 5 ms 768 KB Correct : C = 284
12 Correct 5 ms 768 KB Correct : C = 201
13 Incorrect 5 ms 768 KB Wrong
14 Correct 6 ms 768 KB Correct : C = 289
15 Correct 5 ms 768 KB Correct : C = 198
16 Correct 5 ms 768 KB Correct : C = 286
17 Incorrect 5 ms 640 KB Wrong
18 Correct 5 ms 768 KB Correct : C = 206
19 Correct 5 ms 768 KB Correct : C = 284
20 Correct 5 ms 896 KB Correct : C = 285
21 Correct 5 ms 768 KB Correct : C = 282
22 Correct 5 ms 896 KB Correct : C = 288
23 Correct 5 ms 768 KB Correct : C = 282
24 Correct 5 ms 768 KB Correct : C = 284
25 Correct 5 ms 768 KB Correct : C = 201
26 Correct 5 ms 768 KB Correct : C = 204
27 Correct 5 ms 768 KB Correct : C = 200