Submission #18984230


Source Code Expand

Copy
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
//#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n;
vector<pair<double, int>>vec;
int x[16], y[16], a[16];
double dist[16][16];
struct U{
	int par[16],ran[16];
	void init(){ for(int i=0;i<16;i++) par[i] = i, ran[i] = 0; }
	int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
	void unite(int x,int y){
		x = find(x); y = find(y); if(x==y) return;
		if(ran[x] < ran[y]) par[x] = y;
		else{
			par[y] = x;
			if(ran[x] == ran[y]) ran[x]++;
		}
	}
	bool same(int x,int y){ return find(x)==find(y); }
}kaede;

bool ok[(1<<15)];

int main(){
	cin >> n;
	rep(i, n){
		cin >> x[i] >> y[i] >> a[i];
	}
	rep(i, n){
		rep(j, n){
			dist[i][j] = sqrt( (double)(x[i]-x[j]) * (double)(x[i]-x[j]) + 
				(double)(y[i]-y[j]) * (double)(y[i]-y[j]) );
		}
	}
	repn(mask, (1<<n)-1){
		kaede.init();
		vector<pair<double,P>>E;
		double D = 0.0;
		rep(i, n){
			if( (mask & (1<<i)) == 0 ) continue;
			D += a[i];
			rep(j, i){
				if( (mask & (1<<j)) == 0 ) continue;
				E.pb(mp(dist[i][j], mp(i, j)));
			}
		}
		SORT(E);
		rep(i, E.size()){
			if(kaede.same(E[i].sc.fi, E[i].sc.sc) == false){
				kaede.unite(E[i].sc.fi, E[i].sc.sc);
				D -= E[i].fi;
			}
		}
		D /= (double)(__builtin_popcount(mask));
		vec.pb(mp(D, mask));
	}
	SORT(vec); reverse(vec.begin(), vec.end());
	int lb = -1, ub = vec.size()-1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		memset(ok, 0, sizeof(ok));
		ok[0] = 1;
		rep(i, mid+1){
			int all = (1<<n)-1-vec[i].sc;
			int cur = (1<<n)-1-vec[i].sc;
			while(1){
				ok[cur ^ vec[i].sc] |= ok[cur];
				if(cur == 0) break;
				cur = (cur-1) & all;
			}
			if(ok[(1<<n)-1]) break;
		}
		if(ok[(1<<n)-1]) ub = mid;
		else lb = mid;
	}
	
	printf("%.12f\n", vec[ub].fi);
}

Submission Info

Submission Time
Task E - Water Distribution
User IH19980412
Language C++ (GCC 9.2.1)
Score 1000
Code Size 3129 Byte
Status AC
Exec Time 154 ms
Memory 4084 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:19:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<double, std::pair<int, int> > >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   19 | #define rep(i,x) for(int i=0;i<x;i++)
......
  108 |   rep(i, E.size()){
      |       ~~~~~~~~~~~              
./Main.cpp:108:3: note: in expansion of macro ‘rep’
  108 |   rep(i, E.size()){
      |   ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example0.txt, example1.txt
All 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
Case Name Status Exec Time Memory
000.txt AC 133 ms 4084 KB
001.txt AC 106 ms 3896 KB
002.txt AC 99 ms 3880 KB
003.txt AC 103 ms 3892 KB
004.txt AC 116 ms 3876 KB
005.txt AC 137 ms 3892 KB
006.txt AC 128 ms 3936 KB
007.txt AC 136 ms 4080 KB
008.txt AC 140 ms 4020 KB
009.txt AC 146 ms 3896 KB
010.txt AC 145 ms 3880 KB
011.txt AC 144 ms 4084 KB
012.txt AC 151 ms 3972 KB
013.txt AC 149 ms 3892 KB
014.txt AC 154 ms 4016 KB
015.txt AC 152 ms 3972 KB
016.txt AC 149 ms 4036 KB
017.txt AC 154 ms 4084 KB
018.txt AC 154 ms 4024 KB
019.txt AC 152 ms 3972 KB
020.txt AC 81 ms 3972 KB
021.txt AC 107 ms 4012 KB
022.txt AC 87 ms 3824 KB
023.txt AC 69 ms 3968 KB
024.txt AC 83 ms 3888 KB
025.txt AC 68 ms 3880 KB
026.txt AC 79 ms 3936 KB
027.txt AC 68 ms 3896 KB
028.txt AC 66 ms 3876 KB
029.txt AC 67 ms 3876 KB
030.txt AC 61 ms 3972 KB
031.txt AC 73 ms 3888 KB
032.txt AC 67 ms 3992 KB
033.txt AC 62 ms 4084 KB
034.txt AC 62 ms 3892 KB
035.txt AC 65 ms 3972 KB
036.txt AC 64 ms 4080 KB
037.txt AC 64 ms 4080 KB
038.txt AC 60 ms 3932 KB
039.txt AC 64 ms 4024 KB
040.txt AC 2 ms 3624 KB
041.txt AC 2 ms 3732 KB
042.txt AC 3 ms 3736 KB
043.txt AC 6 ms 3592 KB
example0.txt AC 2 ms 3584 KB
example1.txt AC 99 ms 3972 KB