結果

問題 No.94 圏外です。(EASY)
ユーザー LEDLED
提出日時 2019-01-28 15:55:31
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 849 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 37,792 KB
最終ジャッジ日時 2024-04-15 06:06:18
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,416 KB
testcase_01 AC 85 ms
12,416 KB
testcase_02 AC 79 ms
12,416 KB
testcase_03 AC 78 ms
12,288 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def max(d,n)
	m = d.flatten.compact.sort{|a,b|b<=>a}[n]
	p1 = nil
	p2 = nil
	d.find.with_index{|r,i|
		p1 = i
		r.find.with_index{|c,j|
			p2 = j
			c == m
		}
	}
	[p1,p2,m]
end
def dfs(d,s,g,di,f)
	return true if s == g
	cand = d[s].map.with_index{|e,i|f==i ? nil : e}
	cand.map.with_index{|e,i| !e.nil? && e <= 10.0 ? dfs(d,i,g,e,s) : false}.include?(true)
end
N=gets.to_i
pos=[]
N.times{pos.push(gets.split(/\s/).map(&:to_i))}
d=Array.new(pos.size).map{Array.new(pos.size)}
N.times{|i| N.times{|k| d[i][k]=((pos[i][0]-pos[k][0])**2+(pos[i][1]-pos[k][1])**2)**0.5 if i != k}}
case(d.size)
when 0 then
	puts 1
when 1 then
	puts 2
when 2 then
	puts d[0][1] <= 10.0 ? d[0][1]+2 : 2
else
	f = false
	(0..d.flatten.compact.size/2).each{|num|
		s,g,d0 = max(d,num)
		if dfs(d,s,g,d0,nil)
			f = true
			puts d0+2
			break
		end
	}
	puts 1 unless f
end

0