結果

問題 No.168 ものさし
ユーザー eye_engineeye_engine
提出日時 2019-10-23 23:48:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,984 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 99,660 KB
実行使用メモリ 11,236 KB
最終ジャッジ日時 2023-09-21 19:49:26
合計ジャッジ時間 2,858 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
5,216 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 15 ms
5,092 KB
testcase_12 AC 53 ms
8,548 KB
testcase_13 AC 67 ms
11,036 KB
testcase_14 AC 54 ms
10,952 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 112 ms
10,692 KB
testcase_20 AC 116 ms
11,012 KB
testcase_21 AC 110 ms
10,968 KB
testcase_22 AC 106 ms
11,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

class UnionFind {
 protected:
  vi data;

 public:
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        swap(x, y);
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  //
  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) {
    cin >> x[i] >> y[i];
  }
  vvl d(n, vl(n));
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      ll dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      d[i][j] = dist;
    }
  }
  ll ok = (x[n-1] - x[0]) * (x[n-1] - x[0]) + (y[n-1] - y[0]) * (y[n-1] - y[0]);
  ll ng = 0;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    UnionFind uf(n);
    rep(i, n) {
      rep(j, n) {
        if (i != j && d[i][j] <= mid) {
          uf.unite(i, j);
        }
      }
    }
    if (uf.same(0, n-1)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  ll ans = (ll)sqrt(ok) / 10 * 10;
  while (ans * ans < ok) ans += 10;
  cout << ans << endl;
  return 0;
}
0