結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー ngtkanangtkana
提出日時 2020-04-26 18:40:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 578 ms / 2,000 ms
コード長 3,860 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 226,264 KB
実行使用メモリ 58,280 KB
最終ジャッジ日時 2023-09-30 21:17:38
合計ジャッジ時間 7,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
using path_t=std::vector<std::pair<lint,ld>>;
struct compare_t{
    bool operator()(path_t const& a, path_t const& b)const{return a.back().second>b.back().second;};
};
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;
    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;
    std::vector<std::vector<std::pair<lint,ld>>>g(n);
    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);
        g.at(u).emplace_back(v,w);
        g.at(v).emplace_back(u,w);
    }

    ld inf=numr<ld>::infinity();
    ld eps=1e-7;
    std::vector<path_t>ans;
    auto dijkstra=[&](lint start, auto&&dead)->path_t{
        std::priority_queue<std::pair<ld,lint>>que;
        std::vector<ld>dist(n,inf),prev(n);
        que.emplace(0,start);
        dist.at(start)=0;
        while(!que.empty()){
            lint x=que.top().second;que.pop();
            for(auto[y,w]:g.at(x)){
                ld nd=dist.at(x)+w;
                if(dead.at(y)==2||dead.at(y)==1&&x==start||dist.at(y)-eps<=nd)continue;
                dist.at(y)=nd;
                prev.at(y)=x;
                que.emplace(-nd,y);
            }
        }
        if(dist.at(t)==inf)return {};
        path_t path={{t,dist.at(t)}};
        while(path.back().first!=start){
            lint y=prev.at(path.back().first);
            path.emplace_back(y,dist.at(y));
        }
        return path;
    };
    {
        auto path=dijkstra(s,std::vector<lint>(n,0));
        std::reverse(ALL(path));
        ans.push_back(std::move(path));
    }

    auto coprefix=[](auto&&a,auto&&b,std::size_t l){
        if(a.size()<l||b.size()<l)return false;
        for(std::size_t i=0;i<l;i++){
            if(a.at(i).first!=b.at(i).first)return false;
        }
        return true;
    };

    std::priority_queue<path_t,std::vector<path_t>,compare_t>que;
    for(lint k=1;k<K;k++){
        auto const& b0=ans.back();
        lint l0=b0.size();
        for(lint j=1;j<l0;j++){
            std::vector<lint>dead(n);
            for(auto&&b:ans)if(coprefix(b,b0,j))dead.at(b.at(j).first)=1;
            for(lint j_=0;j_<j;j_++)dead.at(b0.at(j_).first)=2;
            auto path=dijkstra(b0.at(j-1).first,dead);
            if(path.empty())continue;
            for(auto&&p:path)p.second+=b0.at(j-1).second;
            for(lint j_=j-2;j_>=0;j_--)path.push_back(b0.at(j_));
            std::reverse(ALL(path));
            que.push(path);
        }

        bool found=false;
        while(!que.empty()){
            auto path=que.top();que.pop();
            lint sz=path.size();
            bool ng=false;
            for(auto&&b:ans){
                if((lint)b.size()!=sz)continue;
                for(lint i=0;i<=sz;i++){
                    if(i==sz){
                        ng=true;
                        break;
                    }
                    if(path.at(i).first!=b.at(i).first)break;
                }
            }
            if(!ng){
                found=true;
                ans.push_back(path);
                break;
            }
        }
        if(!found)break;
    }

    for(lint i=0;i<K;i++){
        std::cout<<(i<(lint)ans.size()?ans.at(i).back().second:-1)<<'\n';
    }
}
0