結果

問題 No.2179 Planet Traveler
ユーザー tnakao0123tnakao0123
提出日時 2023-01-09 22:58:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 62,684 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2023-08-22 22:00:53
合計ジャッジ時間 2,873 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 5 ms
8,040 KB
testcase_12 AC 12 ms
7,928 KB
testcase_13 WA -
testcase_14 AC 26 ms
7,928 KB
testcase_15 AC 38 ms
8,008 KB
testcase_16 AC 29 ms
7,872 KB
testcase_17 AC 27 ms
8,044 KB
testcase_18 AC 26 ms
7,996 KB
testcase_19 AC 16 ms
7,992 KB
testcase_20 AC 4 ms
4,884 KB
testcase_21 AC 31 ms
7,828 KB
testcase_22 AC 13 ms
7,068 KB
testcase_23 AC 9 ms
7,072 KB
testcase_24 AC 20 ms
7,556 KB
testcase_25 AC 8 ms
7,128 KB
testcase_26 AC 12 ms
7,692 KB
testcase_27 AC 5 ms
4,896 KB
testcase_28 AC 8 ms
7,072 KB
testcase_29 AC 27 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2179.cc:  No.2179 Planet Traveler - yukicoder
 */

#include<cstdio>
#include<cmath>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 800;
const long long MAX_S = 3200000000LL;

/* typedef */

typedef long long ll;
typedef queue<int> qi;

/* global variables */

int xs[MAX_N], ys[MAX_N], ts[MAX_N];
double rs[MAX_N];
ll ds[MAX_N][MAX_N];
bool used[MAX_N];

/* subroutines */

inline ll dist2(int dx, int dy) { return (ll)dx * dx + (ll)dy * dy; }

bool check(int n, ll s) {
  fill(used, used + n, false);
  used[0] = true;

  qi q;
  q.push(0);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (u == n - 1) return true;

    for (int v = 0; v < n; v++)
      if (! used[v] && ds[u][v] <= s) {
	used[v] = true;
	q.push(v);
      }
  }

  return false;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", xs + i, ys + i, ts + i);
    rs[i] = sqrt(dist2(xs[i], ys[i]));
  }

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      if (ts[i] != ts[j]) {
	double dr = rs[j] - rs[i];
	ds[i][j] = ds[j][i] = ceil(dr * dr);
      }
      else
	ds[i][j] = ds[j][i] = dist2(xs[j] - xs[i], ys[j] - ys[i]);
    }

  ll s0 = -1, s1 = MAX_S;
  while (s0 + 1 < s1) {
    ll s = (s0 + s1) / 2;
    if (check(n, s)) s1 = s;
    else s0 = s;
  }

  printf("%lld\n", s1);

  return 0;
}
0