結果
問題 | No.96 圏外です。 |
ユーザー | 👑 hos.lyric |
提出日時 | 2015-02-24 01:20:07 |
言語 | D (dmd 2.106.1) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,503 bytes |
コンパイル時間 | 2,990 ms |
コンパイル使用メモリ | 176,380 KB |
実行使用メモリ | 14,592 KB |
最終ジャッジ日時 | 2024-06-12 02:29:46 |
合計ジャッジ時間 | 10,696 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 10 ms
5,376 KB |
testcase_05 | AC | 19 ms
5,376 KB |
testcase_06 | AC | 30 ms
5,376 KB |
testcase_07 | AC | 46 ms
5,376 KB |
testcase_08 | AC | 65 ms
5,376 KB |
testcase_09 | AC | 89 ms
5,376 KB |
testcase_10 | AC | 120 ms
5,376 KB |
testcase_11 | AC | 153 ms
5,376 KB |
testcase_12 | AC | 195 ms
5,632 KB |
testcase_13 | AC | 253 ms
6,784 KB |
testcase_14 | AC | 302 ms
7,296 KB |
testcase_15 | AC | 384 ms
9,344 KB |
testcase_16 | AC | 446 ms
9,344 KB |
testcase_17 | AC | 516 ms
10,496 KB |
testcase_18 | AC | 548 ms
10,880 KB |
testcase_19 | AC | 549 ms
10,880 KB |
testcase_20 | AC | 577 ms
14,592 KB |
testcase_21 | AC | 296 ms
7,768 KB |
testcase_22 | AC | 273 ms
8,192 KB |
testcase_23 | AC | 349 ms
8,320 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
ソースコード
import core.thread; import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex; // Input class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { tokens = readln.split; if (tokens.empty && stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; } int readInt() { return to!int(readToken); } long readLong() { return to!long(readToken); } real readReal() { return to!real(readToken); } // chmin/chmax void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } // Pair struct Pair(S, T) { S x; T y; int opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; } int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; } string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; } } auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); } // Array int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); } T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; } int root(int[] uf, int u) { return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u])); } bool conn(int[] uf, int u, int v) { u = uf.root(u); v = uf.root(v); if (u == v) return false; if (uf[u] > uf[v]) swap(u, v); uf[u] += uf[v]; uf[v] = u; return true; } int N; int[] X, Y; int det(int a, int b, int c, int d) { return (X[b] - X[a]) * (Y[d] - Y[c]) - (Y[b] - Y[a]) * (X[d] - X[c]); } int tri(int a, int b, int c) { return det(a, b, a, c); } real dist(int a, int b) { return (cast(real)((X[b] - X[a])^^2 + (Y[b] - Y[a])^^2))^^0.5; } real diameter(int[] us) { us.sort!((a, b) => (X[a] < X[b])); int[] vs; foreach (u; us) { for (; vs.length > 1 && tri(vs[$ - 2], vs[$ - 1], u) <= 0; vs.popBack) {} vs ~= u; } const r = vs.length; foreach_reverse (u; us) { for (; vs.length > r && tri(vs[$ - 2], vs[$ - 1], u) <= 0; vs.popBack) {} vs ~= u; } if (vs.length > 1) { vs.popBack; } debug{ writeln("vs = ",vs); } real ret = 0.0; for (int i = 0, j = 1; ; ) { chmax(ret, dist(vs[i % $], vs[j % $])); if (i + 1 == j) { ++j; } else if (j + 1 == i + vs.length) { ++i; } else if (det(vs[i % $], vs[(i + 1) % $], vs[j % $], vs[(j + 1) % $]) > 0) { ++j; } else { ++i; } if (i == vs.length) { break; } } return ret; } void main(string[] args) { Pair!(int, int)[] dirs; foreach (dx; -10 .. +10 + 1) foreach (dy; -10 .. +10 + 1) if (pair(dx, dy) > pair(0, 0)) { if (dx^^2 + dy^^2 <= 10^^2) { dirs ~= pair(dx, dy); } } debug{ writeln("dirs.length = ",dirs.length); } try { for (; ; ) { N = readInt; X = new int[N]; Y = new int[N]; foreach (i; 0 .. N) { X[i] = readInt; Y[i] = readInt; } int encode(int x, int y) { return x * 20000 + y; } /* int[int] ids; foreach (i; 0 .. N) { ids[encode(X[i], Y[i])] = i; } */ auto ps = new Pair!(int, int)[N]; foreach (i; 0 .. N) { ps[i] = pair(encode(X[i], Y[i]), i); } ps.sort(); int[] uf = new int[N]; uf[] = -1; /* foreach (i; 0 .. N) { foreach (dir; dirs) { const key = encode(X[i] + dir.x, Y[i] + dir.y); if (key in ids) { uf.conn(i, ids[key]); } int pos = ps.lowerBound(pair(key, -1)); if (pos < N && ps[pos].x == key) { uf.conn(i, ps[pos].y); } } } */ foreach (dir; dirs) { const diff = encode(dir.x, dir.y); for (int j = 0, k = 0; j < N && k < N; ) { if (ps[k].x - ps[j].x == diff) { debug{ writeln("conn ",ps[j].y," ",ps[k].y); } uf.conn(ps[j].y, ps[k].y); } if (ps[k].x - ps[j].x < diff) { ++k; } else { ++j; } } } int[][] uss = new int[][N]; foreach (u; 0 .. N) { uss[uf.root(u)] ~= u; } debug{ writeln("uss = ",uss); } real ans = 1.0; foreach (us; uss) { if (!us.empty) { const res = diameter(us); chmax(ans, res + 2.0); } } writefln("%.10f", ans); } } catch (EOFException) {} }