結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー hotman78hotman78
提出日時 2020-06-05 03:09:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,072 bytes
コンパイル時間 6,393 ms
コンパイル使用メモリ 435,088 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-08 03:57:14
合計ジャッジ時間 9,143 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 5 ms
6,016 KB
testcase_05 WA -
testcase_06 AC 7 ms
6,144 KB
testcase_07 AC 6 ms
6,528 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,888 KB
testcase_14 AC 6 ms
6,144 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 5 ms
5,760 KB
testcase_22 AC 5 ms
6,400 KB
testcase_23 AC 6 ms
6,272 KB
testcase_24 WA -
testcase_25 AC 6 ms
5,632 KB
testcase_26 AC 6 ms
6,656 KB
testcase_27 AC 6 ms
6,656 KB
testcase_28 AC 6 ms
6,656 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 4 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 WA -
testcase_45 AC 5 ms
5,376 KB
testcase_46 WA -
testcase_47 AC 5 ms
5,376 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 3 ms
5,376 KB
testcase_51 WA -
testcase_52 AC 4 ms
5,376 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 AC 4 ms
5,376 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 5 ms
5,888 KB
testcase_80 WA -
testcase_81 AC 5 ms
5,504 KB
testcase_82 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:51:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   51 | bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |            ^~~~
main.cpp:51:26: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   51 | bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                          ^~~~
main.cpp:52:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   52 | bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |            ^~~~
main.cpp:52:26: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   52 | bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                          ^~~~

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF (9223372036854775807LL)
#define EPS (1e-10)
#define endl ('\n')
//#define MOD 1000000007LL
#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

template<typename T>
struct heap{
    struct node{
        node* ch[2]={0,0};
        int s;
        T val;
        int from,to;
        node(T val,int from,int to):s(1),val(val),from(from),to(to){}
    };
    using np=node*;
    np root=0;
    heap(np t=0):root(t){}
    np meld(np a,np b){
        if(!b)return a?new node(*a):0;
        if(!a)return b?new node(*b):0;
        a=new node(*a);b=new node(*b);
        if(a->val>b->val)swap(a,b);
        a->ch[1]=meld(a->ch[1],b);
        if(!a->ch[0]||a->ch[0]->s<a->ch[1]->s)swap(a->ch[0],a->ch[1]);
        a->s=(a->ch[1]?a->ch[1]->s:0)+1;
        return a;
    }
    heap meld(heap b){
        return heap(meld(root,b.root));
    }
    heap insert(T x,int from,int to){
        return heap(meld(root,new node(x,from,to)));
    }
    heap pop(){
        return heap(meld(root->ch[0],root->ch[1]));
    }
    T top(){
        return root?root->val:T(-1);
    }
    bool empty(){
        return !root;
    }
};

int main(){
    lint n,m,k;
    cin>>n>>m>>k;
    vector<pair<lint,lint>>v(n);
    lint x,y;
    cin>>x>>y;
    x--;y--;
    mat g(n);
    rep(i,n){
        cin>>v[i].first>>v[i].second;
    }
    rep(i,m){
        lint s,t;
        cin>>s>>t;
        s--;t--;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    vector<double>p(n,INF);
    vector<lint>par(n,-1);
    vector<set<lint>> ch(n);
    priority_queue<pair<double,lint>,vector<pair<double,lint>>,greater<pair<double,lint>>>que;
    que.emplace(0,y);
    p[y]=0;
    while(!que.empty()){
        auto [t,n]=que.top();
        que.pop();
        for(auto e:g[n]){
            if(chmin(p[e],t+dist(v[n].first,v[n].second,v[e].first,v[e].second))){
                par[e]=n;
                que.emplace(p[e],e);
            }
        }
    }
    rep(i,n){
        if(par[i]!=-1)ch[par[i]].emplace(i);
    }
    vector<heap<double>>h(n);
    rep(i,n)h[i]=heap<double>();
    queue<lint>qq;
    qq.emplace(y);
    auto d=[&](lint from,lint to){
        return dist(v[from].first,v[from].second,v[to].first,v[to].second)-p[from]+p[to];
    };
    while(!qq.empty()){
        auto n=qq.front();
        qq.pop();
        if(par[n]!=-1)h[n]=h[n].meld(h[par[n]]);
        for(auto e:g[n]){
            if(e!=par[n])h[n]=h[n].insert(d(n,e),n,e);
            if(ch[n].count(e))qq.emplace(e);
        }
    }
    auto comp=[](auto s,auto t){return s.first>t.first;};
    priority_queue<pair<double,heap<double>::np>,vector<pair<double,heap<double>::np>>,decltype(comp)>qqq(comp);
    heap<double>s;
    s=s.insert(p[x],-1,x);
    qqq.emplace(p[x],s.root);
    vector<double>ans;
    while(!qqq.empty()){
        auto [t,now]=qqq.top();
        qqq.pop();
        ans.push_back(t);
        if(int(ans.size())==k)break;
        if(now->ch[0]){
            qqq.emplace(t+now->ch[0]->val-now->val,now->ch[0]);
        }
        if(now->ch[1]){
            qqq.emplace(t+now->ch[1]->val-now->val,now->ch[1]);
        }
        if(h[now->to].root){
            qqq.emplace(t+h[now->to].root->val,h[now->to].root);
        }
    }
    rep(i,k){
        if(i<(int)ans.size())cout<<ans[i]<<endl;
        else cout<<-1<<endl;
    }
}
0