結果
問題 | No.96 圏外です。 |
ユーザー |
👑 |
提出日時 | 2015-02-24 01:20:07 |
言語 | D (dmd 2.109.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 4 |
ソースコード
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;// Inputclass 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/chmaxvoid 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; }// Pairstruct 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); }// Arrayint 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) {}}