結果

問題 No.2179 Planet Traveler
ユーザー CleyLCleyL
提出日時 2023-01-06 23:51:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,517 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 115,124 KB
実行使用メモリ 8,244 KB
最終ジャッジ日時 2023-08-20 17:26:30
合計ジャッジ時間 12,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,388 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 730 ms
8,132 KB
testcase_14 AC 719 ms
8,056 KB
testcase_15 AC 725 ms
7,992 KB
testcase_16 AC 722 ms
8,028 KB
testcase_17 AC 736 ms
8,064 KB
testcase_18 AC 722 ms
8,244 KB
testcase_19 AC 725 ms
8,128 KB
testcase_20 AC 37 ms
4,380 KB
testcase_21 AC 648 ms
7,876 KB
testcase_22 AC 344 ms
6,208 KB
testcase_23 AC 284 ms
5,764 KB
testcase_24 AC 528 ms
7,076 KB
testcase_25 AC 369 ms
6,212 KB
testcase_26 AC 602 ms
7,500 KB
testcase_27 AC 39 ms
4,380 KB
testcase_28 AC 203 ms
5,112 KB
testcase_29 AC 527 ms
6,996 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-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);
  long long x = ceil(sqrt((a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y)));
  if((x-1)*(x-1) == (a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y))x--;
  if(x*x == (a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y)){
    return (a.x*a.x+a.y*a.y)+(b.x*b.x+b.y*b.y)-2*x;
  }else{
    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)*(b.x*b.x+b.y*b.y))));
  }
}

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