結果

問題 No.96 圏外です。
ユーザー fumiphysfumiphys
提出日時 2019-04-27 01:37:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,252 ms / 5,000 ms
コード長 3,553 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 187,780 KB
実行使用メモリ 22,392 KB
最終ジャッジ日時 2023-08-17 04:19:50
合計ジャッジ時間 14,821 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,316 KB
testcase_01 AC 5 ms
7,392 KB
testcase_02 AC 4 ms
7,320 KB
testcase_03 AC 4 ms
7,128 KB
testcase_04 AC 11 ms
7,548 KB
testcase_05 AC 16 ms
7,844 KB
testcase_06 AC 24 ms
7,944 KB
testcase_07 AC 42 ms
8,344 KB
testcase_08 AC 55 ms
8,644 KB
testcase_09 AC 81 ms
9,160 KB
testcase_10 AC 144 ms
9,596 KB
testcase_11 AC 167 ms
10,240 KB
testcase_12 AC 187 ms
11,048 KB
testcase_13 AC 422 ms
11,480 KB
testcase_14 AC 459 ms
12,804 KB
testcase_15 AC 858 ms
13,228 KB
testcase_16 AC 860 ms
15,244 KB
testcase_17 AC 859 ms
17,580 KB
testcase_18 AC 1,252 ms
16,904 KB
testcase_19 AC 1,197 ms
17,052 KB
testcase_20 AC 529 ms
17,816 KB
testcase_21 AC 540 ms
20,340 KB
testcase_22 AC 1,141 ms
22,380 KB
testcase_23 AC 498 ms
22,392 KB
testcase_24 AC 4 ms
7,296 KB
testcase_25 AC 470 ms
14,764 KB
testcase_26 AC 746 ms
16,732 KB
testcase_27 AC 541 ms
15,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes
#include <bits/stdc++.h>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}

typedef struct UnionFind_ {
  vector<int> par;
  vector<int> rank_;
  UnionFind_(int n): rank_(n, 0) {
    for(int i = 0; i < n; i++)par.push_back(i);
  }
  int find(int x) {
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  bool same(int x, int y) {
    if(find(x) == find(y))return true;
    else return false;
  }
  bool unite(int x, int y){
    int xp = find(x);
    int yp = find(y);
    if(xp == yp)return false;
    if(rank_[xp] > rank_[yp])par[yp] = xp;
    else if(rank_[xp] < rank_[yp])par[xp] = yp;
    else {
      par[yp] = xp;
      rank_[xp]++;
    }
    return true;
  }
} UnionFind;

map<int, int> p[20001];
int base = 10000;
vector<int> v[120001];

int get(int i, int j){
  if(p[i + base].find(j) != p[i + base].end())return p[i + base][j];
  return -1;
}

double cross(const Pd &o, const Pd &a, const Pd &b){
  return (a.first - o.first) * (b.second - o.second) - (a.second - o.second) * (b.first - o.first);
}

vector<Pd> convex_hull(vector<Pd> vec){
  int n = vec.size(), k = 0;
  if(n < 3)return vec;

  vector<Pd> ch(2 * n);
  sort(vec.begin(), vec.end());

  // lower
  for(int i = 0; i < n; i++){
    while(k >= 2 && cross(ch[k-2], ch[k-1], vec[i]) <= 0.)k--;
    ch[k++] = vec[i];
  }

  // upper
  for(int i = n - 1, t = k + 1; i > 0; --i){
    while(k >= t && cross(ch[k-2], ch[k-1], vec[i-1]) <= 0.)k--;
    ch[k++] = vec[i-1];
  }

  ch.resize(k - 1);
  return ch;

}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if(n == 0){
    cout << 1 << endl;
    return 0;
  }
  vector<int> x(n), y(n);
  rep(i, n)cin >> x[i] >> y[i];
  rep(i, n){
    p[x[i] + base][y[i]] = i;
  }
  UnionFind uf(n);
  rep(i, n){
    for(int j = -10; j <= 10; j++){
      for(int k = -10; k <= 10; k++){
        int in = get(x[i] + j, y[i] + k);
        if(in >= 0){
          if((x[i] - x[in]) * (x[i] - x[in]) + (y[i] - y[in]) * (y[i] - y[in]) > 100)continue;
          uf.unite(i, in);
        }
      }
    }
  }
  double res = 0;
  rep(i, n){
    v[uf.find(i)].pb(i);
  }
  for(int i = 0; i < n; i++){
    if(uf.find(i) != i)continue;
    vector<Pd> vec;
    for(auto c: v[i]){
      vec.pb(mk(x[c], y[c]));
    }
    vector<Pd> ch = convex_hull(vec);
    rep(j, sz(ch)){
      rep(k, sz(ch)){
        double x1 = ch[j].first, x2 = ch[k].first;
        double y1 = ch[j].second, y2 = ch[k].second;
        res = max(res, (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
      }
    }
  }
  cout << setprecision(20);
  cout << 2. + sqrt(res) << endl;
	return 0;
}
0