CODE FESTIVAL 2016 Grand Final

Submission #4184954

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;

#define MAX 1<<15

int n;

double cost[MAX];

vector<pair<double,double> > v;


double dist(int a,int b){
	return sqrt((v[a].first-v[b].first)*(v[a].first-v[b].first)+(v[a].second-v[b].second)*(v[a].second-v[b].second));
}
struct st{
	int a;
	int b;
	double c;
};
bool operator<(const st a,const st b){
	return a.c<b.c;
}
vector<st> ed;
int belong[MAX];
inline int root(int b){
	if(belong[b]==-1){
		return b;
	}
	return belong[b]=root(belong[b]);
}
inline void merge(int a,int b){
	a=root(a);
	b=root(b);
	if(a==b)return;
	belong[a]=b;
}
double dp[1<<15];
vector<double> C;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		v.push_back({a,b});
		C.push_back(c);
	}
	for(int i=1;i<(1<<n);i++){
		double node=0;
		double num=0;
		memset(belong,-1,sizeof(belong));
		ed.clear();
		for(int j=0;j<n;j++){
			if(((i>>j)&1)==0)continue;
			num+=1;
			node+=C[j];
			for(int k=j+1;k<n;k++){
				if(((i>>k)&1)==0)continue;
				ed.push_back({j,k,dist(j,k)});
			}
		}
		sort(ed.begin(),ed.end());
		for(auto &it:ed){
			if(root(it.a)!=root(it.b)){
				merge(it.a,it.b);
				cost[i]+=it.c;
			}
		}
		node-=cost[i];
		node/=num;
		//cout<<node<<endl;
		node=max(node,0.0);
		cost[i]=node;
	}
	dp[0]=LLONG_MAX;
	for(int i=0;i<(1<<n);i++){
		for(int j=((i+1)|i);j<(1<<n);j++,j|=i){
			int ex=(j^i);
			dp[j]=max(dp[j],min(dp[i],cost[ex]));
		}
	}
	printf("%.16f\n",dp[(1<<n)-1]);
	return 0;
}

Submission

Task問題 E - Water Distribution
User nameユーザ名 Greenland
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1000
Source lengthソースコード長 1538 Byte
File nameファイル名
Exec time実行時間 230 ms
Memory usageメモリ使用量 896 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 1000 / 1000 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,012.txt,013.txt,014.txt,015.txt,016.txt,017.txt,018.txt,019.txt,020.txt,021.txt,022.txt,023.txt,024.txt,025.txt,026.txt,027.txt,028.txt,029.txt,030.txt,031.txt,032.txt,033.txt,034.txt,035.txt,036.txt,037.txt,038.txt,039.txt,040.txt,041.txt,042.txt,043.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 223 ms 896 KB
001.txt AC 226 ms 896 KB
002.txt AC 225 ms 896 KB
003.txt AC 226 ms 896 KB
004.txt AC 226 ms 896 KB
005.txt AC 223 ms 896 KB
006.txt AC 228 ms 896 KB
007.txt AC 223 ms 896 KB
008.txt AC 223 ms 896 KB
009.txt AC 222 ms 896 KB
010.txt AC 224 ms 896 KB
011.txt AC 224 ms 896 KB
012.txt AC 226 ms 896 KB
013.txt AC 221 ms 896 KB
014.txt AC 225 ms 896 KB
015.txt AC 228 ms 896 KB
016.txt AC 220 ms 896 KB
017.txt AC 226 ms 896 KB
018.txt AC 223 ms 896 KB
019.txt AC 224 ms 896 KB
020.txt AC 223 ms 896 KB
021.txt AC 230 ms 896 KB
022.txt AC 230 ms 896 KB
023.txt AC 224 ms 896 KB
024.txt AC 225 ms 896 KB
025.txt AC 220 ms 896 KB
026.txt AC 225 ms 896 KB
027.txt AC 220 ms 896 KB
028.txt AC 217 ms 896 KB
029.txt AC 217 ms 896 KB
030.txt AC 216 ms 896 KB
031.txt AC 223 ms 896 KB
032.txt AC 216 ms 896 KB
033.txt AC 215 ms 896 KB
034.txt AC 212 ms 896 KB
035.txt AC 214 ms 896 KB
036.txt AC 215 ms 896 KB
037.txt AC 215 ms 896 KB
038.txt AC 216 ms 896 KB
039.txt AC 216 ms 896 KB
040.txt AC 2 ms 384 KB
041.txt AC 2 ms 384 KB
042.txt AC 2 ms 384 KB
043.txt AC 3 ms 384 KB
example0.txt AC 2 ms 384 KB
example1.txt AC 223 ms 896 KB