結果

問題 No.2179 Planet Traveler
ユーザー HIcoderHIcoder
提出日時 2023-07-12 09:03:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,555 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 109,768 KB
実行使用メモリ 6,904 KB
最終ジャッジ日時 2023-10-11 23:09:07
合計ジャッジ時間 7,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 227 ms
6,732 KB
testcase_14 AC 175 ms
6,844 KB
testcase_15 AC 173 ms
6,660 KB
testcase_16 AC 171 ms
6,588 KB
testcase_17 AC 238 ms
6,528 KB
testcase_18 AC 241 ms
6,692 KB
testcase_19 AC 235 ms
6,584 KB
testcase_20 AC 37 ms
4,352 KB
testcase_21 AC 242 ms
6,376 KB
testcase_22 AC 163 ms
5,672 KB
testcase_23 AC 136 ms
5,380 KB
testcase_24 AC 200 ms
6,152 KB
testcase_25 AC 158 ms
5,916 KB
testcase_26 AC 209 ms
6,384 KB
testcase_27 AC 36 ms
4,348 KB
testcase_28 AC 113 ms
5,208 KB
testcase_29 AC 202 ms
6,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);

/*
// abs(√a - √b) <= √cかどうかの判定
bool f(ll a,ll b,ll c){


    //ll t=(a*a + b*b + c*c)-(2*a*b + 2*b*c + 2*c*a);
    //t<=0

    ll t=(a*a + b*b + c*c)/(2*a*b +2*b*c + 2*c*a);

    return t<=1;
}
*/

/*
bool f(ll a,ll b,ll c){   
    double t=abs(sqrt(a) - sqrt(b));

    return t<=sqrt(c);
}
*/
/*
bool f(ll a,ll b,ll c){   
    //ll t=(a+b-c)/(4*a*b)*(a+b-c);

     ll t=(a+b-c)*(a+b-c)/(4*a*b);


    ll u=abs(a+b-c);

    if(u>(INF/u)) return false;

    return t<=1;
}
*/

int main(){

    int N;
    cin>>N;
    vector<ll> X(N),Y(N),T(N);
    for(int i=0;i<N;i++){
        cin>>X[i]>>Y[i]>>T[i];
    }


    auto f=[&](int i,int j){
        if(T[i]==T[j]){ 
            return (X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        }else{
            //T[i]!=T[j]

            ll R1s=X[i]*X[i]+Y[i]*Y[i];
            ll R2s=X[j]*X[j]+Y[j]*Y[j];
            return R1s+R2s - (ll)sqrt(4*R1s*R2s);
        }

    };

    ll ub=INF,lb=-1;
    //ubのときは必ずたどり着ける
    while(ub>lb+1){

        ll mid=(ub+lb)/2;

        vector<vector<int>> G(N);

        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                // ll a=X[i]*X[i]+Y[i]*Y[i];
                // ll b=X[j]*X[j]+Y[j]*Y[j];

                if(f(i,j)<=mid){
                    //iとjに辺が張れる
                    G[i].push_back(j);
                    G[j].push_back(i);
                    
                }

            }
        }
        /*
        for(int i=0;i<N;i++){
            cout<<"i="<<i<<endl;
            for(int v:G[i]){
                cout<<"v="<<v<<endl;
            }
        }
        */


        //bfs
        vector<ll> dp(N,INF);
        dp[0]=0;//惑星0がスタート
        queue<int> que;
        que.push(0);

        while(!que.empty()){

            int now=que.front();
            que.pop();
            for(int to:G[now]){
                if(dp[to]==INF){
                    dp[to]=dp[now]+1;
                    que.push(to);
                }
            }
        }

        if(dp[N-1]!=INF){
            //midで到達できる
            ub=mid;
            
        }else{
            lb=mid;
            
        }

    }

    cout<<ub<<endl;

}
0