結果

問題 No.96 圏外です。
ユーザー nebukuro09
提出日時 2018-04-12 16:56:28
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 1,334 ms / 5,000 ms
コード長 3,183 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 184,652 KB
実行使用メモリ 38,072 KB
最終ジャッジ日時 2024-06-13 00:24:06
合計ジャッジ時間 13,992 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto P = N.iota.map!(_ => readln.split.map!(to!int)).map!(a => Point(a[0], a[1])).array;
if (N == 0) {
writeln(1);
return;
}
Tuple!(int, int)[][int] X;
foreach (i, p; P.enumerate) {
X[p.x] ~= tuple(p.y, i.to!int);
}
foreach (k; X.keys) X[k].sort();
auto uf = new UnionFind(N);
foreach (i, p; P.enumerate) {
foreach (dx; -10..11) {
int nx = p.x + dx;
if (nx !in X) continue;
int j = X[nx].assumeSorted.lowerBound(tuple(p.y, 0)).length.to!int;
for (int k = j; k < X[nx].length; ++k) {
int ny = X[nx][k][0];
if (dx * dx + (ny - p.y) * (ny - p.y) > 100) break;
if (nx != p.x || ny != p.y) uf.unite(i.to!int, X[nx][k][1]);
}
for (int k = min(j, X[nx].length.to!int-1); k >= 0; --k) {
int ny = X[nx][k][0];
if (dx * dx + (ny - p.y) * (ny - p.y) > 100) break;
if (nx != p.x || ny != p.y) uf.unite(i.to!int, X[nx][k][1]);
}
}
}
int farest = 0;
foreach (i; 0..N) {
if (uf.groups[i].empty) continue;
auto ch = convex_hull(uf.groups[i].map!(i => P[i]).array);
foreach (j; 0..ch.length) {
foreach (k; j+1..ch.length) {
farest = max(farest, dist2(ch[j], ch[k]));
}
}
}
writefln("%.9f", sqrt(farest * 1.0L) + 2);
}
struct Point {
int x;
int y;
}
Point[] convex_hull(Point[] points) {
int N = points.length.to!int;
points.sort!((a, b) => a.x == b.x ? a.y < b.y : a.x < b.x);
Point[] ch1, ch2;
foreach (i; 0..N) {
while (ch1.length >= 2 && rot(ch1[$-2], ch1[$-1], points[i]) <= 0) ch1.popBack;
ch1 ~= points[i];
}
foreach_reverse (i; 0..N) {
while (ch2.length >= 2 && rot(ch2[$-2], ch2[$-1], points[i]) <= 0) ch2.popBack;
ch2 ~= points[i];
}
auto ch = ch1 ~ ch2;
return ch.sort!((a, b) => a.x == b.x ? a.y < b.y : a.x < b.x).uniq.array;
}
int rot(Point a, Point b, Point c) {
// a -> b -> c
// 0
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
int dist2(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
class UnionFind {
int N;
int[] table;
int[][] groups;
this(int n) {
N = n;
table = new int[](N);
fill(table, -1);
groups = new int[][](N);
foreach (i; 0..N) groups[i] = [i];
}
int find(int x) {
return table[x] < 0 ? x : (table[x] = find(table[x]));
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (table[x] > table[y]) swap(x, y);
table[x] += table[y];
table[y] = x;
groups[x] ~= groups[y];
groups[y] = [];
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0