結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2017-03-08 05:45:31 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,547 ms / 2,000 ms |
コード長 | 1,527 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 130,940 KB |
最終ジャッジ日時 | 2024-12-24 07:18:19 |
合計ジャッジ時間 | 14,952 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
Syntax OK
ソースコード
# frozen_string_literal: truerequire 'bigdecimal'module Graphclass Nodeattr_reader :id, :x, :ydef initialize(id, x, y)@id = id@x = x@y = y@parent = selfenddef powered_length(other)(@x - other.x)**2 + (@y - other.y)**2enddef founder?@parent == selfenddef ancestorif founder?selfelse@parent.ancestorendenddef same?(other)ancestor == other.ancestorenddef union!(other)if founder?if ancestor.id >= other.ancestor.id@parent = other.ancestorelseother.union!(self)endelse@parent.ancestor.union!(other)endendendclass Edgeattr_reader :weightdef initialize(a, b)@a = a@b = b@weight = @a.powered_length(@b)enddef same?@a.same?(@b)enddef union!@a.union!(@b)endendenddef int_sqrt(n, k)BigDecimal(n).sqrt(Math.log10(n).to_i).ceil(k).to_iendn = gets.to_ilist = Array.new(n) { gets.split.map(&:to_i)}node_list = list.each_with_index.map { |xy, i| Graph::Node.new(i, xy[0], xy[1]) }edge_list = node_list.product(node_list).reject { |a, b| a == b }.map { |a, b| Graph::Edge.new(a, b) }.sort_by(&:weight)max_weight = 0edge_list.each do |edge|break if node_list.last.ancestor == node_list.firstunless edge.same?edge.union!max_weight = edge.weightendendputs int_sqrt(max_weight, -1)