結果
問題 | No.1069 電柱 / Pole (Hard) |
ユーザー |
![]() |
提出日時 | 2020-04-26 19:21:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,146 bytes |
コンパイル時間 | 2,884 ms |
コンパイル使用メモリ | 211,300 KB |
最終ジャッジ日時 | 2025-01-10 02:04:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 RE * 57 MLE * 3 |
ソースコード
/* * bruteforce solution by bit DP */ #include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; template<class T>using numr=std::numeric_limits<T>; struct input_t{template<class T>operator T(){T t;std::cin>>t;return t;}}input; template<std::size_t N,class T,class...Args>auto mkvec(std::size_t sz,Args...args){ if constexpr(N==1)return std::vector<T>(sz,args...); else return std::vector(sz,mkvec<N-1,T>(args...)); } int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n=input,m=input,K=input; assert(n<=25); lint N=1ll<<n; lint s=input,t=input;s--,t--; std::vector<std::pair<ld,ld>>pt(n); for(auto&&p:pt)std::cin>>p.first>>p.second; ld inf=numr<ld>::infinity(); auto adj=mkvec<2,ld>(n,n,inf); for(lint i=0;i<n;i++)adj.at(i).at(i)=0; while(m--){ lint u=input,v=input;u--,v--; ld w=std::hypot(pt.at(u).first-pt.at(v).first,pt.at(u).second-pt.at(v).second); adj.at(u).at(v)=w; adj.at(v).at(u)=w; } auto insert=[&](auto&&v, ld x){ assert((lint)v.size()==K); assert(std::is_sorted(ALL(v))); auto it=std::lower_bound(ALL(v),x); if(it==v.end())return; v.insert(it,x); v.pop_back(); }; auto dp=mkvec<3,ld>(N,n,K,inf); dp.at(1ll<<s).at(s).at(0)=0; for(lint bs=1ll<<s;bs<N;bs++,bs|=1ll<<s)for(lint i=0;i<n;i++)if(bs>>i&1ll){ for(lint k=0;k<K;k++)if(dp.at(bs).at(i).at(k)!=inf){ ld now=dp.at(bs).at(i).at(k); for(lint j=0;j<n;j++)if(!(bs>>j&1ll)){ ld d=adj.at(i).at(j); if(d==inf)continue; insert(dp.at(bs|1ll<<j).at(j),now+d); } } } std::vector<ld>ans; for(lint bs=1ll<<t;bs<N;bs++,bs|=1ll<<t){ for(lint k=0;k<K;k++){ ans.push_back(dp.at(bs).at(t).at(k)); } } std::sort(ALL(ans)); ans.resize(K,-1); for(ld d:ans){ if(d==inf)std::cout<<-1<<'\n'; else std::cout<<d<<'\n'; } }