結果

問題 No.96 圏外です。
ユーザー koba-e964koba-e964
提出日時 2017-01-06 13:34:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,881 ms / 5,000 ms
コード長 2,621 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 78,732 KB
実行使用メモリ 117,924 KB
最終ジャッジ日時 2023-08-25 22:12:24
合計ジャッジ時間 10,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
106,988 KB
testcase_01 AC 36 ms
106,904 KB
testcase_02 AC 35 ms
106,984 KB
testcase_03 AC 36 ms
106,788 KB
testcase_04 AC 38 ms
107,112 KB
testcase_05 AC 39 ms
107,268 KB
testcase_06 AC 42 ms
107,492 KB
testcase_07 AC 46 ms
107,700 KB
testcase_08 AC 48 ms
108,160 KB
testcase_09 AC 54 ms
108,564 KB
testcase_10 AC 58 ms
108,736 KB
testcase_11 AC 67 ms
109,808 KB
testcase_12 AC 88 ms
110,992 KB
testcase_13 AC 85 ms
110,864 KB
testcase_14 AC 95 ms
112,716 KB
testcase_15 AC 158 ms
113,168 KB
testcase_16 AC 126 ms
115,636 KB
testcase_17 AC 142 ms
117,924 KB
testcase_18 AC 142 ms
117,416 KB
testcase_19 AC 144 ms
116,876 KB
testcase_20 AC 1,513 ms
114,296 KB
testcase_21 AC 1,881 ms
115,868 KB
testcase_22 AC 1,329 ms
114,296 KB
testcase_23 AC 1,324 ms
114,160 KB
testcase_24 AC 37 ms
106,820 KB
testcase_25 AC 109 ms
114,608 KB
testcase_26 AC 134 ms
117,000 KB
testcase_27 AC 119 ms
115,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>

/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
const double EPS=1e-9;

const int N = 120001;
int x[N], y[N];

const int W = 2100;
const int B = 10;
const int TH = 200;
VI board[W][W];


ll solve(const vector<int> &t) {
  int n = t.size();
  ll ma = 0;
  if (n <= TH) {
    REP(j, 0, n) {
      REP(k, j + 1, n) {
	int a = t[j];
	int b = t[k];
	ll dist = (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);
	ma = max(ma, dist);
      }
    }
    return ma;
  }
  // rotation
  REP(i, 0, TH) {
    double pi = acos(-1.0);
    double s = sin(pi * i / TH);
    double c = cos(pi * i / TH);
    typedef pair<double, int> PDI;
    vector<PDI> ss(n);
    REP(i, 0, n) {
      ss[i] = PDI(c * x[t[i]] + s * y[t[i]], t[i]);
    }
    sort(ss.begin(), ss.end());
    int u = ss[0].second;
    int v = ss[ss.size() - 1].second;
    ma = max(ma, ll(x[u] - x[v]) * (x[u] - x[v]) + (y[u] - y[v]) * (y[u] - y[v]));
  }
  return ma;
}

int main(void){
  int n;
  cin >> n;
  if (n == 0) {
    cout << 1 << endl;
    return 0;
  }
  const int BIAS = 10000;
  UnionFind uf(n);
  REP(i, 0, n) {
    cin >> x[i] >> y[i];
    x[i] += BIAS;
    y[i] += BIAS;
    board[x[i] / B][y[i] / B].push_back(i);
  }
  REP(i, 0, n) {
    REP(a, -1, 2) {
      REP(b, -1, 2) {
	if (x[i] / B + a < 0 || y[i] / B + b < 0) { continue; }
	VI &neighbor = board[x[i] / B + a][y[i] / B + b];
	REP(k, 0, neighbor.size()) {
	  int j = neighbor[k];
	  int dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
	  if (dist <= 100) {
	    uf.unite(i, j);
	  }
	}
      }
    }
  }
  ll ma = 0;
  vector<VI> conn(n);
  REP(i, 0, n) {
    conn[uf.root(i)].push_back(i);
  }
  REP(i, 0, n) {
    VI &t = conn[i];
    ma = max(ma, solve(t));
  }
  printf("%.15f\n", 2 + sqrt(ma));
}
0