結果

問題 No.1265 Balloon Survival
ユーザー tamura2004tamura2004
提出日時 2021-01-23 18:12:21
言語 Crystal
(1.10.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 18,358 ms
コンパイル使用メモリ 260,488 KB
実行使用メモリ 30,552 KB
最終ジャッジ日時 2023-09-13 13:15:26
合計ジャッジ時間 21,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,476 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,496 KB
testcase_11 AC 2 ms
4,432 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,408 KB
testcase_14 AC 17 ms
8,356 KB
testcase_15 AC 14 ms
7,436 KB
testcase_16 AC 6 ms
5,412 KB
testcase_17 AC 68 ms
20,548 KB
testcase_18 AC 8 ms
5,532 KB
testcase_19 AC 7 ms
5,548 KB
testcase_20 AC 17 ms
8,396 KB
testcase_21 AC 33 ms
11,372 KB
testcase_22 AC 23 ms
11,252 KB
testcase_23 AC 24 ms
11,392 KB
testcase_24 AC 129 ms
29,656 KB
testcase_25 AC 133 ms
29,564 KB
testcase_26 AC 130 ms
29,532 KB
testcase_27 AC 129 ms
30,552 KB
testcase_28 AC 128 ms
29,916 KB
testcase_29 AC 129 ms
29,528 KB
testcase_30 AC 129 ms
30,080 KB
testcase_31 AC 130 ms
29,312 KB
testcase_32 AC 128 ms
29,608 KB
testcase_33 AC 127 ms
29,612 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 2点間の距離と点番号を求めて、距離の小さい順にソート
# 小さい順に取り出す
# 既に破裂した点が含まれている→何もしない
# 1番の点が含まれている->相手の点を破裂扱いにし、取り除く点に+1
# それ以外→両方の点を破裂扱いにする

n = gets.to_s.to_i
xy = Array.new(n){ gets.to_s.split.map { |v| v.to_i64 - 1} }

dists = [] of Tuple(Int64,Int32,Int32)
n.times do |i|
  n.times do |j|
    next unless i < j
    xi,yi = xy[i]
    xj,yj = xy[j]
    dist = (yi - yj) ** 2 + (xi - xj) ** 2
    dists << {dist, i, j}
  end
end

bang = Array.new(n, false)
ans = 0_i64
dists.sort.each do |d, i, j|
  next if bang[i] || bang[j]
  if i == 0
    bang[j] = true
    ans += 1
  else
    bang[i] = true
    bang[j] = true
  end
end
puts ans
0