結果
問題 | No.2179 Planet Traveler |
ユーザー |
👑 |
提出日時 | 2023-01-06 23:35:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,280 bytes |
コンパイル時間 | 1,154 ms |
コンパイル使用メモリ | 114,960 KB |
最終ジャッジ日時 | 2025-02-10 00:30:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 WA * 3 |
ソースコード
//yukicoder@cpp17#include <iostream>#include <cmath>#include <algorithm>#include <iomanip>#include <string>#include <vector>#include <set>#include <stack>#include <queue>#include <map>#include <bitset>#include <complex>#include <cctype>#include <utility>#include <climits>#include <numeric>using namespace std;using ll = long long;using P = pair<ll,ll>;const ll MOD = 998244353;const ll MODx = 1000000007;const int INF = (1<<30)-1;const ll LINF = (1LL<<62LL)-1;const double EPS = (1e-5);P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }/*確認ポイントcout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる計算量は変わらないが楽できるシリーズmin(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくるcount(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる*//*function corner below*//*Function corner above*//* comment outed because can cause bugs__attribute__((constructor))void initial() {cin.tie(0);ios::sync_with_stdio(false);}*/template <typename C>class FloydWarshall {C MAX;void run(){for(int k = 0; n > k; k++){for(int i = 0; n > i; i++){for(int j = 0; n > j; j++){if(dist[i][k] == MAX || dist[k][j] == MAX)continue;dist[i][j] = min(dist[i][j],max(dist[i][k],dist[k][j]));}}}}public:int n;vector<vector<C>> dist;//MAX以上なら辺はなしFloydWarshall(int n_,C MAX = 2e18+1):n(n_),MAX(MAX),dist(n_,vector<C>(n_,MAX)){for(int i = 0; n > i; i++){dist[i][i] = 0;}}//双方向void push(int s,int v,C c){dist[s][v] = min(dist[s][v],c);dist[v][s] = min(dist[s][v],c);}void update(int s,int v,C c){dist[s][v] = c;dist[v][s] = c;}void push_p(int s,int v,C c){dist[s][v] = min(dist[s][v],c);}void update_p(int s,int v,C c){dist[s][v] = c;}bool negative(){for(int i = 0; n > i; i++){if(dist[i][i] < 0)return true;}return false;}bool isInf(int s,int v){return dist[s][v] == MAX;}void build(){run();}};struct d{long long x,y,d;};bool operator<(d a, d b){return a.x*a.x+a.y*a.y < b.x*b.x+b.y*b.y;}long long dist(d a,d b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}long long dist2(d a, d b){long long ans = (a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y);return ceil((long double)(a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y)-((long double)2*sqrt(a.x*a.x+a.y*a.y)*sqrt(b.x*b.x+b.y*b.y))-EPS);}int main(){int n;cin>>n;vector<d> A(n);for(int i = 0; n > i; i++){cin>>A[i].x>>A[i].y>>A[i].d;}FloydWarshall<long long> B(n);for(int i = 0; n > i; i++){for(int j = 1+i; n > j; j++){if(A[i].d == A[j].d){B.push(i,j,dist(A[i],A[j]));}else{B.push(i,j,dist2(A[i],A[j]));}}}B.build();cout << B.dist[0][n-1] << endl;}