結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー ngtkanangtkana
提出日時 2020-04-26 19:21:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,146 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 213,112 KB
実行使用メモリ 814,244 KB
最終ジャッジ日時 2024-04-24 05:06:32
合計ジャッジ時間 6,619 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 TLE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 5 ms
6,940 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 5 ms
6,944 KB
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 147 ms
106,128 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 5 ms
6,940 KB
testcase_55 AC 633 ms
460,560 KB
testcase_56 AC 2 ms
6,944 KB
testcase_57 MLE -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * 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';
    }
}
0