結果

問題 No.168 ものさし
ユーザー ei1333333ei1333333
提出日時 2015-07-26 20:08:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,417 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 154,544 KB
実行使用メモリ 13,164 KB
最終ジャッジ日時 2023-08-25 20:58:35
合計ジャッジ時間 2,699 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,280 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 12 ms
5,244 KB
testcase_12 AC 41 ms
13,132 KB
testcase_13 AC 57 ms
12,900 KB
testcase_14 AC 57 ms
12,864 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 54 ms
12,420 KB
testcase_20 AC 56 ms
11,424 KB
testcase_21 AC 56 ms
13,164 KB
testcase_22 AC 56 ms
11,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
#define ABS(a, b) max(a - b, b - a)
#define SQR(a) ((int64)(a)*(int64)(a))
struct edge {
  int u, v;
  int64 cost;
  bool operator<(const edge& e) const {
    return(cost < e.cost);
  }
};

struct UnionFind {
  vector< int > data;
  UnionFind(int sz){
    data.assign(sz, -1);
  }
  int Find(int x){
    return(data[x] < 0 ? x : data[x] = Find(data[x]));
  }
  void Unite(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return;
    if(data[a] < data[b]) swap(a, b);
    data[b] += data[a];
    data[a] = b;
  }
  bool Same(int a, int b) {
    return(Find(a) == Find(b));
  }
};
  
int main()
{
  int N, X[1000], Y[1000];
  cin >> N;
  UnionFind uf(N);
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  vector< edge > edges;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      edges.push_back((edge){i, j, SQR(ABS(X[i], X[j])) + SQR(ABS(Y[i], Y[j]))});
    }
  }
  sort(edges.begin(), edges.end());

  int64 ret = 0;

  for(int i = 0; i < edges.size(); i++) {
    edge& e = edges[i];
    if(uf.Same(e.u, e.v)) continue;
    ret = e.cost;
    uf.Unite(e.u, e.v);
    if(uf.Same(0, N - 1)) break;
  }
  int64 low = 0, high = 1LL << 32;
  while(high - low > 0) {
    int64 mid = (low + high) >> 1LL;
    if(SQR(mid) >= ret) high = mid;
    else low = mid + 1;
  }
  cout << (low + 9) / 10 * 10 << endl;
}
0