結果

問題 No.2179 Planet Traveler
ユーザー milanis48663220milanis48663220
提出日時 2023-01-06 22:32:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 3,000 ms
コード長 3,737 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 122,108 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 15:48:26
合計ジャッジ時間 4,724 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 100 ms
4,380 KB
testcase_12 AC 143 ms
4,380 KB
testcase_13 AC 141 ms
4,380 KB
testcase_14 AC 94 ms
4,376 KB
testcase_15 AC 93 ms
4,380 KB
testcase_16 AC 94 ms
4,380 KB
testcase_17 AC 140 ms
4,380 KB
testcase_18 AC 140 ms
4,376 KB
testcase_19 AC 137 ms
4,376 KB
testcase_20 AC 20 ms
4,380 KB
testcase_21 AC 134 ms
4,376 KB
testcase_22 AC 86 ms
4,380 KB
testcase_23 AC 74 ms
4,380 KB
testcase_24 AC 111 ms
4,376 KB
testcase_25 AC 88 ms
4,376 KB
testcase_26 AC 121 ms
4,376 KB
testcase_27 AC 20 ms
4,376 KB
testcase_28 AC 59 ms
4,380 KB
testcase_29 AC 114 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

/**
 * https://kenkoooo.hatenablog.com/entry/2016/11/30/163533
 * より。Project Eularであまりにも使うので。
 */

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream & operator >> (istream &in,  __int128_t &m){
    string s; cin >> s;
    m = parse(s);
    return in;
}


ostream &operator<<(std::ostream &dest, __int128_t value) {
    ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = end(buffer);
        do {
        --d;
        *d = "0123456789"[tmp % 10];
        tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
        --d;
        *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
        dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}

using ll = __int128_t;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> x(n), y(n), t(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> t[i];
    auto ok = [&](ll p){
        UnionFind uf(n);
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(t[i] == t[j]){
                    ll dx = x[i]-x[j];
                    ll dy = y[i]-y[j];
                    ll sum = dx*dx+dy*dy;
                    if(sum <= p) uf.unionSet(i, j);
                }else{
                    ll a = x[i]*x[i]+y[i]*y[i];
                    ll b = x[j]*x[j]+y[j]*y[j];
                    ll sum = a+b-p;
                    if(sum <= 0 || sum*sum <= 4*a*b) uf.unionSet(i, j);
                }
            }
        }
        return uf.findSet(0, n-1);
    };
    if(ok(0)){
        cout << 0 << endl;
        return 0;
    }
    ll l = 0, r = 1e18;
    while(r-l > 1){
        ll p = (l+r)/2;
        if(ok(p)) r = p;
        else l = p;
    }
    cout << r << endl;
}
0