結果
問題 | No.168 ものさし |
ユーザー | siman |
提出日時 | 2017-09-17 22:12:57 |
言語 | Ruby (3.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,922 bytes |
コンパイル時間 | 44 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 61,440 KB |
最終ジャッジ日時 | 2024-11-08 01:58:56 |
合計ジャッジ時間 | 11,332 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 333 ms
23,168 KB |
testcase_01 | AC | 88 ms
12,416 KB |
testcase_02 | AC | 86 ms
12,160 KB |
testcase_03 | AC | 88 ms
12,416 KB |
testcase_04 | AC | 87 ms
12,416 KB |
testcase_05 | WA | - |
testcase_06 | AC | 88 ms
12,160 KB |
testcase_07 | AC | 86 ms
12,032 KB |
testcase_08 | WA | - |
testcase_09 | AC | 95 ms
12,544 KB |
testcase_10 | AC | 115 ms
13,440 KB |
testcase_11 | AC | 307 ms
23,040 KB |
testcase_12 | AC | 826 ms
47,872 KB |
testcase_13 | AC | 1,128 ms
61,440 KB |
testcase_14 | AC | 1,090 ms
61,312 KB |
testcase_15 | AC | 86 ms
12,288 KB |
testcase_16 | AC | 91 ms
12,288 KB |
testcase_17 | AC | 103 ms
12,928 KB |
testcase_18 | AC | 138 ms
14,592 KB |
testcase_19 | AC | 1,077 ms
59,904 KB |
testcase_20 | AC | 1,128 ms
61,184 KB |
testcase_21 | AC | 1,128 ms
61,184 KB |
testcase_22 | AC | 1,142 ms
61,184 KB |
コンパイルメッセージ
Main.rb:142: warning: assigned but unused variable - check_list Syntax OK
ソースコード
class UnionFind def initialize(n) @size = Array.new(n, 1) @parent = [] n.times do |i| @parent[i] = i end end def find(x) if @parent[x] == x x else @parent[x] = find(@parent[x]) end end def unite(x, y) x = find(x) y = find(y) return if x == y @parent[y] = x @size[x] += @size[y] end def same(x, y) find(x) == find(y) end def size(x) @size[find(x)] end end class PriorityQueue attr_reader :size def initialize(order: :asc) @size = 0 @nodes = [] @operator = (order == :asc) ? [:>, :<] : [:<, :>] end def empty? @size.zero? end def push(node) if @nodes[0].nil? @nodes[0] = node else index = size @nodes[index] = node loop { parent = (index-1)/2 if (@nodes[parent].last <=> node.last).public_send(@operator.first, 0) @nodes[index], @nodes[parent] = @nodes[parent], @nodes[index] index = parent break if index.zero? else break end } end @size += 1 end alias_method :<<, :push def pop node = @nodes.first @nodes[0], @nodes[size - 1] = @nodes[size - 1], nil index = 0 loop { left = 2*index+1 right = 2*index+2 if @nodes[left].nil? && @nodes[right].nil? break elsif @nodes[left] && @nodes[right] target = (@nodes[left].last <=> @nodes[right].last).public_send(@operator.last, 0) ? left : right if (@nodes[target].last <=> @nodes[index].last).public_send(@operator.last, 0) @nodes[index], @nodes[target] = @nodes[target], @nodes[index] index = target else break end elsif @nodes[left] if (@nodes[left].last <=> @nodes[index].last).public_send(@operator.last, 0) @nodes[index], @nodes[left] = @nodes[left], @nodes[index] index = left else break end elsif @nodes[right] if (@nodes[right].last <=> @nodes[index].last).public_send(@operator.last, 0) @nodes[index], @nodes[right] = @nodes[right], @nodes[index] index = right else break end end } @size -= 1 node.first end def top @nodes.first end end N = gets.to_i points = [] N.times do points << gets.chomp.split.map(&:to_i) end pque = PriorityQueue.new 0.upto(N-2) do |i| (i+1).upto(N-1) do |j| p1 = points[i] p2 = points[j] dist = Math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) pque.push([[i, j, dist], dist]) end end check_list = {} max_d = 0 uf = UnionFind.new(N) until pque.empty? i, j, dist = pque.pop if uf.find(i) != uf.find(j) uf.unite(i, j) max_d = [max_d, dist].max break if uf.find(0) == uf.find(N-1) end end if max_d % 10 == 0 puts max_d.to_i else puts 10 * (max_d.to_i / 10 + 1) end