結果

問題 No.2179 Planet Traveler
ユーザー eve__fuyukieve__fuyuki
提出日時 2023-11-29 12:50:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 3,000 ms
コード長 1,419 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 219,484 KB
実行使用メモリ 12,076 KB
最終ジャッジ日時 2023-11-29 12:50:47
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 42 ms
12,076 KB
testcase_12 AC 91 ms
12,076 KB
testcase_13 AC 92 ms
12,076 KB
testcase_14 AC 38 ms
12,076 KB
testcase_15 AC 40 ms
12,076 KB
testcase_16 AC 39 ms
12,076 KB
testcase_17 AC 84 ms
12,076 KB
testcase_18 AC 83 ms
12,076 KB
testcase_19 AC 84 ms
12,076 KB
testcase_20 AC 13 ms
6,676 KB
testcase_21 AC 79 ms
12,076 KB
testcase_22 AC 51 ms
7,932 KB
testcase_23 AC 46 ms
7,932 KB
testcase_24 AC 67 ms
7,936 KB
testcase_25 AC 53 ms
7,932 KB
testcase_26 AC 75 ms
12,076 KB
testcase_27 AC 13 ms
6,676 KB
testcase_28 AC 36 ms
7,928 KB
testcase_29 AC 67 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
long long sq_floor(long long x) {
    long long lo = 0, hi = 5e9;
    while (lo + 1 < hi) {
        long long mid = (lo + hi) / 2;
        if (mid * mid <= x) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<long long> x(n), y(n), t(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> t[i];
    }
    vector<long long> r(n);
    for (int i = 0; i < n; i++) {
        r[i] = x[i] * x[i] + y[i] * y[i];
    }
    vector<tuple<long long, int, int>> edges;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (t[i] == t[j]) {
                edges.push_back({(x[i] - x[j]) * (x[i] - x[j]) +
                                     (y[i] - y[j]) * (y[i] - y[j]),
                                 i, j});
            } else {
                edges.push_back(
                    {r[i] + r[j] - sq_floor((long long)r[i] * r[j] * 4), i, j});
            }
        }
    }
    sort(edges.begin(), edges.end());
    dsu uf(n);
    for (auto [w, u, v] : edges) {
        uf.merge(u, v);
        if (uf.same(0, n - 1)) {
            cout << w << endl;
            return 0;
        }
    }
}
0