結果

問題 No.2179 Planet Traveler
ユーザー CleyLCleyL
提出日時 2023-01-06 23:33:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,280 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 115,008 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-08-20 17:06:46
合計ジャッジ時間 11,027 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 629 ms
8,024 KB
testcase_12 AC 641 ms
8,028 KB
testcase_13 WA -
testcase_14 AC 623 ms
8,084 KB
testcase_15 AC 624 ms
8,024 KB
testcase_16 AC 621 ms
8,124 KB
testcase_17 AC 637 ms
8,024 KB
testcase_18 AC 633 ms
8,072 KB
testcase_19 AC 632 ms
8,144 KB
testcase_20 AC 32 ms
4,376 KB
testcase_21 AC 561 ms
7,920 KB
testcase_22 AC 300 ms
6,232 KB
testcase_23 AC 252 ms
5,812 KB
testcase_24 AC 456 ms
7,068 KB
testcase_25 AC 320 ms
6,228 KB
testcase_26 AC 524 ms
7,652 KB
testcase_27 AC 33 ms
4,376 KB
testcase_28 AC 178 ms
5,292 KB
testcase_29 AC 462 ms
7,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//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-8);

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;
}
0