結果

問題 No.2179 Planet Traveler
ユーザー 👑 NachiaNachia
提出日時 2023-01-06 22:10:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 3,000 ms
コード長 3,103 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 83,052 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 15:20:18
合計ジャッジ時間 2,988 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 4 ms
4,384 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 64 ms
4,380 KB
testcase_18 AC 67 ms
4,384 KB
testcase_19 AC 30 ms
4,384 KB
testcase_20 AC 4 ms
4,384 KB
testcase_21 AC 69 ms
4,384 KB
testcase_22 AC 34 ms
4,380 KB
testcase_23 AC 13 ms
4,380 KB
testcase_24 AC 48 ms
4,380 KB
testcase_25 AC 5 ms
4,384 KB
testcase_26 AC 22 ms
4,380 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 12 ms
4,384 KB
testcase_29 AC 57 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#line 2 "nachia\\math\\floor-of-kth-root.hpp"

#include <cassert>

namespace nachia{

namespace internal{

// mod 2^64
constexpr unsigned long long PowerOfULongLong(unsigned long long a, unsigned long long i){
    unsigned long long res = 1;
    while(i){ if(i&1){ res *= a; } i /= 2; a *= a; }
    return res;
}

}

unsigned long long FloorOfKthRoot(unsigned long long real, unsigned long long k){
    using u64 = unsigned long long;
    assert(k != 0);
    if(real <= 1) return real;
    if(k >= 64) return 1;
    if(k == 1) return real;
    struct Precalc{
        // a^i <= x
        static constexpr bool lesseq(u64 a, int i, u64 x) {
            if (a == 0) return true;
            for(int j=0; j<i; j++) x /= a;
            return x >= 1;
        }
        unsigned long long BORDER[64];
        constexpr Precalc() : BORDER() {
            for (int idx = 2; idx <= 63; idx++) {
                u64 l = 0, r = 1ull << 33;
                while (l + 1 < r) {
                    u64 m = (l + r) / 2;
                    if (lesseq(m, idx, ~0ull)) l = m;
                    else r = m;
                }
                BORDER[idx] = r;
            }
        };
    };
    constexpr Precalc precalc;
    u64 l = 0, r = precalc.BORDER[k];
    while (l + 1 < r) {
        u64 m = (l + r) / 2;
        if(internal::PowerOfULongLong(m, k) <= real) l = m;
        else r = m;
    }
    return l;
}

unsigned long long CeilOfKthRoot(unsigned long long real, unsigned long long k){
    if(real <= 1) return real;
    if(k >= 64) return 2;
    if(k == 1) return real;
    unsigned long long x = FloorOfKthRoot(real, k);
    if(internal::PowerOfULongLong(x, k) != real) x++;
    return x;
}

} // namespace nachia
#line 8 "Main.cpp"
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


int main(){
    int N; cin >> N;
    vector<i64> X(N), Y(N), T(N);
    rep(i,N) cin >> X[i] >> Y[i] >> T[i];
    vector<i64> Q(N, INF);
    vector<int> vis(N);
    vector<int> bfs = {0};
    auto dist = [&](int a, int b) -> i64 {
        if(T[a] == T[b]) return (X[a]-X[b])*(X[a]-X[b])+(Y[a]-Y[b])*(Y[a]-Y[b]);
        i64 asq = X[a]*X[a]+Y[a]*Y[a];
        i64 bsq = X[b]*X[b]+Y[b]*Y[b];
        return asq + bsq - nachia::FloorOfKthRoot(4 * asq * bsq, 2);
    };
    i64 ans = 0;
    Q[0] = 0;
    rep(i,N){
        int s = bfs[i];
        ans = max(ans, Q[s]);
        vis[s] = 1;
        if(s == N-1) break;
        rep(j,N) if(vis[j] == 0) Q[j] = min(Q[j], dist(s,j));
        int nx = -1;
        rep(j,N) if(vis[j] == 0) if(nx == -1 || Q[nx] > Q[j]) nx = j;
        bfs.push_back(nx);
    }
    cout << ans << endl;
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0