結果
問題 | No.96 圏外です。 |
ユーザー |
|
提出日時 | 2017-04-21 11:23:16 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 502 ms / 5,000 ms |
コード長 | 2,836 bytes |
コンパイル時間 | 2,421 ms |
コンパイル使用メモリ | 167,992 KB |
実行使用メモリ | 192,624 KB |
最終ジャッジ日時 | 2024-06-12 18:47:52 |
合計ジャッジ時間 | 7,160 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 20 ms
36,352 KB |
testcase_05 | AC | 35 ms
40,616 KB |
testcase_06 | AC | 40 ms
43,860 KB |
testcase_07 | AC | 25 ms
17,956 KB |
testcase_08 | AC | 51 ms
50,896 KB |
testcase_09 | AC | 58 ms
48,128 KB |
testcase_10 | AC | 52 ms
18,456 KB |
testcase_11 | AC | 95 ms
52,768 KB |
testcase_12 | AC | 121 ms
71,536 KB |
testcase_13 | AC | 103 ms
24,984 KB |
testcase_14 | AC | 146 ms
59,784 KB |
testcase_15 | AC | 155 ms
28,736 KB |
testcase_16 | AC | 189 ms
58,456 KB |
testcase_17 | AC | 218 ms
77,644 KB |
testcase_18 | AC | 236 ms
74,628 KB |
testcase_19 | AC | 246 ms
68,280 KB |
testcase_20 | AC | 502 ms
192,624 KB |
testcase_21 | AC | 228 ms
81,276 KB |
testcase_22 | AC | 322 ms
17,796 KB |
testcase_23 | AC | 328 ms
17,048 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 174 ms
74,108 KB |
testcase_26 | AC | 204 ms
75,480 KB |
testcase_27 | AC | 184 ms
74,648 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.math; void main() { auto n = readln.chomp.to!size_t; auto pi = n.iota.map!(_ => readln.split.to!(int[])).map!(rd => point(rd[0], rd[1])).array; if (n == 0) { writeln(1); return; } auto minX = pi.map!"a.x".minElement; auto minY = pi.map!"a.y".minElement; foreach (ref p; pi) { p.x -= minX; p.y -= minY; } auto maxX = pi.map!"a.x".maxElement, maxBx = maxX / 10; auto maxY = pi.map!"a.y".maxElement, maxBy = maxY / 10; auto bucket = new size_t[][][](maxBy + 1, maxBx + 1); foreach (i, p; pi) bucket[p.y / 10][p.x / 10] ~= i; auto uf = UnionFind!size_t(n); foreach (i, p; pi) for (auto by = p.y / 10 - 1; by <= p.y / 10 + 1; ++by) for (auto bx = p.x / 10 - 1; bx <= p.x / 10 + 1; ++bx) { if (bx < 0 || bx > maxBx || by < 0 || by > maxBy) continue; foreach (ti; bucket[by][bx]) { if (i >= ti || (p - pi[ti]).hypot2 > 100) continue; uf.unite(i, ti); } } auto gi = new size_t[][](n); foreach (i; 0..n) gi[uf.find(i)] ~= i; auto gpi = gi.filter!"!a.empty".map!(g => pi.indexed(g).array.convexHull); auto maxD = 0; foreach (gp; gpi) foreach (i; 0..gp.length) foreach (j; i+1..gp.length) maxD = max(maxD, (gp[i] - gp[j]).hypot2); writefln("%.7f", maxD.to!real.sqrt + 2); } struct UnionFind(T) { T[] p; // parent const T s; // sentinel this(T n) { p = new T[](n); s = n + 1; p[] = s; } T find(T i) { if (p[i] == s) { return i; } else { p[i] = find(p[i]); return p[i]; } } void unite(T i, T j) { auto pi = find(i), pj = find(j); if (pi != pj) p[pj] = pi; } } struct Point(T) { T x, y; pure auto opBinary(string op: "+")(Point!T rhs) const { return Point!T(x + rhs.x, y + rhs.y); } pure auto opBinary(string op: "-")(Point!T rhs) const { return Point!T(x - rhs.x, y - rhs.y); } pure auto opBinary(string op: "*")(Point!T rhs) const { return x * rhs.x + y * rhs.y; } pure auto opBinary(string op: "*")(T a) const { return Point!T(x * a, y * a); } pure auto hypot2() const { return x ^^ 2 + y ^^ 2; } } alias Point!int point; Point!T[] convexHull(T)(Point!T[] pi) { if (pi.length <= 2) return pi; auto cross(Point!T a, Point!T b, Point!T o) { return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); } pi.sort!"a.x == b.x ? a.y < b.y : a.x < b.x"; Point!T[] lower; foreach (p; pi) { while (lower.length >= 2 && cross(lower[$-2], lower[$-1], p) <= 0) lower.length -= 1; lower ~= p; } Point!T[] upper; foreach_reverse (p; pi) { while (upper.length >= 2 && cross(upper[$-2], upper[$-1], p) <= 0) upper.length -= 1; upper ~= p; } return (lower.dropBackOne ~ upper.dropBackOne).array; }