結果

問題 No.96 圏外です。
ユーザー koba-e964koba-e964
提出日時 2015-06-20 16:57:54
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,093 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 8,772 KB
最終ジャッジ日時 2023-09-21 22:10:59
合計ジャッジ時間 8,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,772 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/*
 * 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 = 121001;
double x[N], y[N];

const int W = 3000;
vector<int> idx[W];

int main(void){
  int n;
  cin >> n;
  if (n == 0) {
    cout << 1 << endl;
    return 0;
  }
  UnionFind uf(n);
  srand(time(0));
  double rot = (rand() % 360) / 180.0 * acos(-1);
  REP(i, 0, n) {
    double p, q;
    cin >> p >> q;
    x[i] = cos(rot) * p + sin(rot) * q + 15000;
    y[i] = -sin(rot) * p + cos(rot) * q + 15000;
    idx[(int)x[i] / 10].push_back(i);
  }
  REP(w, 0, W) {
    REP(a, 0, idx[w].size()) {
      int i = idx[w][a];
      REP(v, w, w + 12) {
	REP(b, 0, idx[v].size()) {
	  int j = idx[v][b];
	  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);
	  }
	}
      }
    }
  }
  double ma = 0;
  REP(i, 0, n) {
    REP(j, 0, n) {
      REP(w, 0, W) {
	REP(a, 0, idx[w].size()) {
	  int i = idx[w][a];
	  REP(v, w, w + 2) {
	    REP(b, 0, idx[v].size()) {
	      if (uf.is_same_set(i, j)) {
		double dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
		ma = max(ma, dist);
	      }
	    }
	  }
	}
      }
    }
  }
  printf("%.9f\n", 2 + sqrt(ma));
}
0