結果

問題 No.1265 Balloon Survival
ユーザー 小野寺健小野寺健
提出日時 2021-11-02 10:37:14
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 549 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 44,780 KB
最終ジャッジ日時 2024-04-19 16:47:00
合計ジャッジ時間 31,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,416 KB
testcase_01 AC 82 ms
12,160 KB
testcase_02 AC 83 ms
12,160 KB
testcase_03 AC 77 ms
12,416 KB
testcase_04 AC 74 ms
12,160 KB
testcase_05 AC 77 ms
12,160 KB
testcase_06 AC 75 ms
12,288 KB
testcase_07 AC 77 ms
12,288 KB
testcase_08 AC 80 ms
12,416 KB
testcase_09 AC 78 ms
12,288 KB
testcase_10 AC 77 ms
12,288 KB
testcase_11 AC 77 ms
12,288 KB
testcase_12 AC 78 ms
12,160 KB
testcase_13 AC 76 ms
12,288 KB
testcase_14 AC 337 ms
15,872 KB
testcase_15 AC 265 ms
14,848 KB
testcase_16 AC 139 ms
12,928 KB
testcase_17 AC 1,191 ms
25,856 KB
testcase_18 AC 173 ms
13,312 KB
testcase_19 AC 143 ms
12,928 KB
testcase_20 AC 325 ms
15,872 KB
testcase_21 AC 655 ms
20,608 KB
testcase_22 AC 399 ms
16,640 KB
testcase_23 AC 452 ms
17,536 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 AC 77 ms
12,160 KB
testcase_35 AC 78 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:27: warning: assigned but unused variable - d
Syntax OK

ソースコード

diff #

n = gets.to_i
xy = []
n.times {
	xy << gets.split(" ").map{|s| s.to_i}
}

dist = []

max = 0
0.upto(n-1) {|i|
	xi, yi = xy[i]
	(i+1).upto(n-1) {|j|
		xj, yj = xy[j]
		d = (xi-xj)**2 + (yi-yj)**2
		max = d if i == 0 and max < d
		dist << [d, i, j] if d <= max
	}
}

dist.sort!

alive = Array.new(n, true)
alive_n = n
remove = 0

while alive_n > 1 do
	d, i, j = dist.shift
	if i == 0 and alive[j] then
		remove += 1
		alive[j] = false
		alive_n -= 1
	elsif alive[i] and alive[j] then
		alive[i] = alive[j] = false
		alive_n -= 2
	end
end

puts remove
0