結果

問題 No.96 圏外です。
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-24 01:20:07
言語 D
(dmd 2.106.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,503 bytes
コンパイル時間 6,776 ms
コンパイル使用メモリ 171,792 KB
実行使用メモリ 15,504 KB
最終ジャッジ日時 2023-09-02 20:06:46
合計ジャッジ時間 10,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 11 ms
4,368 KB
testcase_05 AC 19 ms
4,528 KB
testcase_06 AC 30 ms
4,616 KB
testcase_07 AC 46 ms
4,668 KB
testcase_08 AC 65 ms
4,820 KB
testcase_09 AC 88 ms
4,912 KB
testcase_10 AC 118 ms
6,472 KB
testcase_11 AC 152 ms
5,488 KB
testcase_12 AC 192 ms
7,768 KB
testcase_13 AC 247 ms
8,292 KB
testcase_14 AC 298 ms
8,120 KB
testcase_15 AC 376 ms
10,624 KB
testcase_16 AC 441 ms
10,304 KB
testcase_17 AC 510 ms
13,212 KB
testcase_18 AC 544 ms
13,508 KB
testcase_19 AC 537 ms
13,944 KB
testcase_20 AC 571 ms
15,504 KB
testcase_21 AC 303 ms
8,292 KB
testcase_22 AC 308 ms
10,376 KB
testcase_23 AC 397 ms
10,488 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 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) {}
}
0