Submission #1564394
Source Code Expand
#include<iostream> #include<cmath> #include<iomanip> #include<cstdio> #include<algorithm> #include<set> #include<map> #include<queue> #include<cassert> #define PB push_back #define MP make_pair #define sz(v) (in((v).size())) #define forn(i,n) for(in i=0;i<(n);++i) #define forv(i,v) forn(i,sz(v)) #define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i) #define all(v) (v).begin(),(v).end() using namespace std; typedef long long in; typedef vector<in> VI; typedef vector<VI> VVI; in p2(in a){ return 1LL<<a; } struct unifnd{ VI ht,pr; in fnd(in a){ in ta=a; while(a!=pr[a])a=pr[a]; in tt=ta; while(ta!=a){ tt=pr[ta]; pr[ta]=a; ta=tt; } return a; } void uni(in a, in b){ a=fnd(a); b=fnd(b); if(a==b)return; if(ht[b]<ht[a])swap(a,b); pr[a]=b; ht[b]+=(ht[a]==ht[b]); } void ini(in n){ ht.resize(n); pr.resize(n); forn(i,n){ ht[i]=0; pr[i]=i; } } }; unifnd tfd; vector<double> x,y,a; vector<double> bspan; vector<pair<double,pair<in,in> > > egs; double sq(double d){ return d*d; } double dist(in i, in j){ return sqrt(sq(x[i]-x[j])+sq(y[i]-y[j])); } vector<double> btot; int main(){ ios::sync_with_stdio(0); cin.tie(0); in n; cin>>n; x=y=a=vector<double>(n); forn(i,n){ cin>>x[i]>>y[i]>>a[i]; } forn(i,n){ forn(j,i){ egs.PB(MP(dist(i,j),MP(i,j))); } } sort(all(egs)); bspan.resize(p2(n)); bspan[0]=2e9; in ta,tb; forn(msk,p2(n)){ if(!msk) continue; double tsm=0; in tcnt=0; tfd.ini(n); forn(i,n){ if(msk&p2(i)){ tsm+=a[i]; ++tcnt; } } for(auto& eg:egs){ ta=eg.second.first; tb=eg.second.second; if((msk&p2(ta))&&(msk&p2(tb))){ if(tfd.fnd(ta)!=tfd.fnd(tb)){ tfd.uni(ta,tb); tsm-=eg.first; } } } bspan[msk]=max(0.0,tsm/tcnt); } btot.resize(p2(n)); btot[0]=2e9; forn(msk,p2(n)){ if(!msk) continue; for(in lmsk=msk;lmsk>0;lmsk=(lmsk-1)&msk){ btot[msk]=max(btot[msk],min(btot[msk^lmsk],bspan[lmsk])); } } cout<<setprecision(15); cout<<btot[p2(n)-1]<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Water Distribution |
User | w4yneb0t |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 2269 Byte |
Status | AC |
Exec Time | 42 ms |
Memory | 768 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
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 | 40 ms | 768 KB |
001.txt | AC | 42 ms | 768 KB |
002.txt | AC | 42 ms | 768 KB |
003.txt | AC | 41 ms | 768 KB |
004.txt | AC | 42 ms | 768 KB |
005.txt | AC | 39 ms | 768 KB |
006.txt | AC | 41 ms | 768 KB |
007.txt | AC | 41 ms | 768 KB |
008.txt | AC | 40 ms | 768 KB |
009.txt | AC | 41 ms | 768 KB |
010.txt | AC | 41 ms | 768 KB |
011.txt | AC | 40 ms | 768 KB |
012.txt | AC | 42 ms | 768 KB |
013.txt | AC | 42 ms | 768 KB |
014.txt | AC | 41 ms | 768 KB |
015.txt | AC | 41 ms | 768 KB |
016.txt | AC | 42 ms | 768 KB |
017.txt | AC | 41 ms | 768 KB |
018.txt | AC | 41 ms | 768 KB |
019.txt | AC | 42 ms | 768 KB |
020.txt | AC | 41 ms | 768 KB |
021.txt | AC | 41 ms | 768 KB |
022.txt | AC | 41 ms | 768 KB |
023.txt | AC | 42 ms | 768 KB |
024.txt | AC | 41 ms | 768 KB |
025.txt | AC | 41 ms | 768 KB |
026.txt | AC | 41 ms | 768 KB |
027.txt | AC | 41 ms | 768 KB |
028.txt | AC | 41 ms | 768 KB |
029.txt | AC | 41 ms | 768 KB |
030.txt | AC | 41 ms | 768 KB |
031.txt | AC | 41 ms | 768 KB |
032.txt | AC | 41 ms | 768 KB |
033.txt | AC | 41 ms | 768 KB |
034.txt | AC | 39 ms | 768 KB |
035.txt | AC | 41 ms | 768 KB |
036.txt | AC | 41 ms | 768 KB |
037.txt | AC | 41 ms | 768 KB |
038.txt | AC | 41 ms | 768 KB |
039.txt | AC | 41 ms | 768 KB |
040.txt | AC | 1 ms | 256 KB |
041.txt | AC | 1 ms | 256 KB |
042.txt | AC | 1 ms | 256 KB |
043.txt | AC | 1 ms | 256 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 41 ms | 768 KB |