結果
問題 | No.2179 Planet Traveler |
ユーザー | t98slider |
提出日時 | 2023-01-06 23:25:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,448 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 180,616 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-05-07 23:18:50 |
合計ジャッジ時間 | 38,857 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | WA | - |
testcase_08 | AC | 9 ms
6,944 KB |
testcase_09 | AC | 8 ms
6,940 KB |
testcase_10 | AC | 7 ms
6,944 KB |
testcase_11 | WA | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | AC | 74 ms
6,940 KB |
testcase_15 | AC | 76 ms
6,940 KB |
testcase_16 | AC | 74 ms
6,944 KB |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 1,920 ms
6,940 KB |
testcase_23 | WA | - |
testcase_24 | AC | 2,578 ms
6,940 KB |
testcase_25 | AC | 2,077 ms
6,940 KB |
testcase_26 | AC | 2,798 ms
6,944 KB |
testcase_27 | WA | - |
testcase_28 | AC | 1,337 ms
6,940 KB |
testcase_29 | AC | 2,578 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define codefor int test;cin>>test;while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) using namespace std; using ll = long long; template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> istream& operator>>(istream& is, vector<T>& vec) {for(T& x : vec)is >> x;return is;} template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {if(vec.empty())return os;os << vec[0];for(auto it = vec.begin(); ++it!= vec.end();)os << ' ' << *it;return os;} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){cin >> head;in(tail...);} void out(){cout << '\n';} template<class T>void out(const T& a){cout << a << '\n';} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){cout << head << ' ';out(tail...);} const int INF = 1 << 30; const long long INF2 = 1ll << 60; template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} struct dsu { public: int csz; dsu() : _n(0) {} dsu(int n) : _n(n), csz(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); csz--; parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; int main(){ ios::sync_with_stdio(false); cin.tie(0); INT(n); vector<tuple<ll,ll,ll>> a(n); ll x, y, t, x1, y1, t1; for(int i = 0; i < n; i++){ cin >> x >> y >> t; a[i] = make_tuple(x, y, t); } auto g = [&](ll s, ll x, ll y, ll x1, ll y1){ ll c1 = x * x + y * y, c2 = x1 * x1 + y1 * y1; ll c = c1 + c2 - s; if(c1 == c2) return true; if(c1 < c2)swap(c1, c2); ll ok = 0, ng = 1ll << 30, mid; while(ok + 1 < ng){ mid = (ok + ng) / 2; if(mid * mid <= c1 * c2)ok = mid; else ng = mid; } return (c1 + c2 - 2 * ok <= s); }; auto f = [&](ll s){ dsu uf(n); for(int i = 0; i < n; i++){ tie(x, y, t) = a[i]; for(int j = i + 1; j < n; j++){ tie(x1, y1, t1) = a[j]; if(t != t1){ if(g(s, x, y, x1, y1))uf.merge(i, j); }else{ ll dx = x - x1, dy = y - y1; if(dx * dx + dy * dy <= s)uf.merge(i, j); } } } return uf.same(0, n - 1); }; ll ng = -1, ok = 1ll << 60, mid; while(ng + 1 < ok){ mid = (ng + ok) / 2; if(f(mid))ok = mid; else ng = mid; } out(ok); }