結果
| 問題 | No.168 ものさし |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-03-24 19:34:42 |
| 言語 | Ruby (4.0.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 970 bytes |
| 記録 | |
| コンパイル時間 | 268 ms |
| コンパイル使用メモリ | 8,832 KB |
| 実行使用メモリ | 66,736 KB |
| 最終ジャッジ日時 | 2026-03-18 08:50:57 |
| 合計ジャッジ時間 | 18,992 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 TLE * 4 |
コンパイルメッセージ
Syntax OK
ソースコード
require 'set'
Problem168 = Struct.new(:points) do
def solve
@distance_cache = {}
w = isqrt(squared_distance_by_index(0, points.size - 1)) / 10
p 10 * (1..w + 1).bsearch {|d| reach? d }
end
private
def isqrt(x)
(1..x).bsearch {|r| x <= r ** 2 }
end
def reach?(d)
sqlen = (d * 10) ** 2
goal = points.size - 1
stack = [0]
done = Set.new
while i = stack.pop
done << i
points.each_index do |j|
if !done.include?(j) && squared_distance_by_index(i, j) <= sqlen
return true if j.equal?(goal)
stack << j
end
end
end
false
end
def squared_distance_by_index(ia, ib)
ia, ib = ib, ia if ib < ia
@distance_cache[ia * points.size + ib] ||= squared_distance(points[ia], points[ib])
end
def squared_distance(a, b)
ax, ay = a
bx, by = b
(ax - bx) ** 2 + (ay - by) ** 2
end
end
Problem168.new((1..gets.to_i).map{gets.split.map(&:to_i)}).solve