結果

問題 No.96 圏外です。
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-24 01:03:21
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 3,837 bytes
コンパイル時間 4,223 ms
コンパイル使用メモリ 167,296 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-09-02 20:02:48
合計ジャッジ時間 19,455 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 719 ms
4,372 KB
testcase_05 AC 2,117 ms
4,616 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 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 == N) {
			break;
		}
	}
	return ret;
}

void main(string[] args) {
	Pair!(int, int)[] dirs;
	foreach (dx; -10 .. +10 + 1) foreach (dy; -10 .. +10 + 1) {
		if (dx^^2 + dy^^2 <= 10^^2) {
			dirs ~= pair(dx, dy);
		}
	}
	
	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;
		}
		
		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[][] 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) {}
}
0