結果

問題 No.245 貫け!
ユーザー yuruhiyayuruhiya
提出日時 2021-05-06 20:51:44
言語 Crystal
(1.11.2)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 531 bytes
コンパイル時間 19,283 ms
コンパイル使用メモリ 255,960 KB
実行使用メモリ 7,484 KB
最終ジャッジ日時 2023-10-12 13:18:51
合計ジャッジ時間 20,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,464 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,428 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,356 KB
testcase_07 AC 2 ms
4,416 KB
testcase_08 AC 3 ms
4,608 KB
testcase_09 AC 6 ms
4,864 KB
testcase_10 AC 8 ms
5,000 KB
testcase_11 AC 23 ms
5,880 KB
testcase_12 AC 56 ms
7,452 KB
testcase_13 AC 56 ms
7,484 KB
testcase_14 AC 55 ms
7,380 KB
testcase_15 AC 55 ms
7,392 KB
testcase_16 AC 55 ms
7,408 KB
testcase_17 AC 56 ms
7,460 KB
testcase_18 AC 56 ms
7,460 KB
testcase_19 AC 57 ms
7,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct Point
  property x : Int32
  property y : Int32

  def initialize(@x, @y)
  end
end

def intersect(p1, p2, p3, p4)
  ((p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x)) *
    ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) <= 0
end

n = read_line.to_i
a1, a2 = (1..n).map {
  a, b, c, d = read_line.split.map(&.to_i)
  [Point.new(a, b), Point.new(c, d)]
}.transpose
puts (a1 + a2).permutations(2).max_of { |(p1, p2)|
  p1 == p2 ? 0 : (0...n).count { |i|
    intersect(p1, p2, a1[i], a2[i])
  }
}
0