結果

問題 No.168 ものさし
ユーザー simansiman
提出日時 2021-06-02 11:19:13
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 2,349 bytes
コンパイル時間 2,677 ms
コンパイル使用メモリ 141,156 KB
実行使用メモリ 18,684 KB
最終ジャッジ日時 2024-04-26 22:42:21
合計ジャッジ時間 3,872 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
9,448 KB
testcase_01 AC 6 ms
5,592 KB
testcase_02 AC 6 ms
5,724 KB
testcase_03 AC 5 ms
5,724 KB
testcase_04 AC 6 ms
5,724 KB
testcase_05 AC 6 ms
5,772 KB
testcase_06 AC 6 ms
5,852 KB
testcase_07 AC 6 ms
5,852 KB
testcase_08 AC 6 ms
5,724 KB
testcase_09 AC 6 ms
6,088 KB
testcase_10 AC 8 ms
6,548 KB
testcase_11 AC 26 ms
9,184 KB
testcase_12 AC 88 ms
15,612 KB
testcase_13 AC 141 ms
18,432 KB
testcase_14 AC 143 ms
18,684 KB
testcase_15 AC 6 ms
5,728 KB
testcase_16 AC 6 ms
5,936 KB
testcase_17 AC 7 ms
6,016 KB
testcase_18 AC 10 ms
6,304 KB
testcase_19 AC 134 ms
18,172 KB
testcase_20 AC 138 ms
18,552 KB
testcase_21 AC 140 ms
18,556 KB
testcase_22 AC 140 ms
18,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 200000;
vector<int> parent;
vector<int> _rank;
vector<int> _size;

class UnionFind {
public:
  UnionFind(int n) {
    for (int i = 0; i < n; ++i) {
      parent.push_back(i);
      _rank.push_back(0);
      _size.push_back(1);
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (_rank[x] < _rank[y]) {
      parent[x] = y;
      _size[y] += _size[x];
    } else {
      parent[y] = x;
      _size[x] += _size[y];
      if (_rank[x] == _rank[y]) ++_rank[x];
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return _size[find(x)];
  }
};

struct Edge {
  ll u;
  ll v;
  ll dist;

  Edge(ll u = -1, ll v = -1, ll dist = -1) {
    this->u = u;
    this->v = v;
    this->dist = dist;
  }

  bool operator>(const Edge &n) const {
    return dist > n.dist;
  }
};

int main() {
  int N;
  cin >> N;

  priority_queue <Edge, vector<Edge>, greater<Edge>> pque;
  vector<Edge> edges;
  ll x, y;
  for (int i = 0; i < N; ++i) {
    cin >> x >> y;
    edges.push_back(Edge(x, y));
  }

  for (int i = 0; i < N; ++i) {
    Edge e1 = edges[i];

    for (int j = i + 1; j < N; ++j) {
      Edge e2 = edges[j];
      ll dy = e1.u - e2.u;
      ll dx = e1.v - e2.v;
      ll dist = dy * dy + dx * dx;
      pque.push(Edge(i, j, dist));
    }
  }

  UnionFind uf(MAX_N);
  ll max_dist = 0;

  while (not pque.empty()) {
    Edge edge = pque.top();
    pque.pop();

    if (uf.same(0, N - 1)) continue;
    if (uf.same(edge.u, edge.v)) continue;
    // fprintf(stderr, "[%d, %d, %lld]\n", edge.u, edge.v, edge.dist);
    uf.unite(edge.u, edge.v);
    max_dist = max(max_dist, edge.dist);
  }

  ll ng = 0;
  ll ok = 3037000499;

  while (abs(ok - ng) >= 2) {
    ll x = (ok + ng) / 2;

    if (x * x >= max_dist) {
      ok = x;
    } else {
      ng = x;
    }
  }

  if (ok % 10 == 0) {
    cout << ok << endl;
  } else {
    cout << 10 * ((ok /10) + 1) << endl;
  }
  return 0;
}

0