結果

問題 No.2179 Planet Traveler
ユーザー yamake
提出日時 2023-01-06 22:31:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 173 ms / 3,000 ms
コード長 1,666 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 207,332 KB
最終ジャッジ日時 2025-02-10 00:10:04
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<"\n";
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const int inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

double eps = -0.00000001;

double dist(array<lint,3> a,array<lint,3> b){
    if(a[2]==b[2]){
        return sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]));
    }
    return abs(sqrt(a[0]*a[0]+a[1]*a[1])-sqrt(b[0]*b[0]+b[1]*b[1]));
}

signed main(){
    int n;cin>>n;
    vector<array<lint,3>> a(n);
    rep(i,n)rep(j,3)cin>>a[i][j];
    vector<vector<array<lint,2>>> edge(n+1);
    rep(i,n){
        rep(j,i){
            edge[i].push_back({j,(lint)ceil(dist(a[i],a[j])*dist(a[i],a[j])+eps)});
            edge[j].push_back({i,(lint)ceil(dist(a[i],a[j])*dist(a[i],a[j])+eps)});
        }
    }
    vector<lint> dp(n+1,linf);
    priority_queue<array<lint,2>,vector<array<lint,2>>,greater<array<lint,2>>> que;
    dp[0]=0;
    que.push({0,0});
    vector<bool> seen(n,false);
    while(!que.empty()){
        auto [d,v]=que.top();que.pop();
        if(seen[v])continue;
        seen[v]=true;
        for(auto& e:edge[v]){
            chmin(dp[e[0]],max(d,e[1]));
            que.push({max(d,e[1]),e[0]});
        }
    }
    // rep(i,n)debug(dp[i]);
    cout<<dp[n-1]<<"\n";
    return 0;
}
0