結果

問題 No.245 貫け!
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-08-24 13:11:19
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 672 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 11,580 KB
実行使用メモリ 20,156 KB
最終ジャッジ日時 2023-09-25 16:41:57
合計ジャッジ時間 11,284 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,344 KB
testcase_01 AC 80 ms
15,060 KB
testcase_02 AC 83 ms
15,172 KB
testcase_03 AC 79 ms
15,096 KB
testcase_04 AC 82 ms
15,256 KB
testcase_05 AC 85 ms
15,244 KB
testcase_06 AC 83 ms
15,320 KB
testcase_07 AC 79 ms
15,024 KB
testcase_08 AC 139 ms
15,476 KB
testcase_09 AC 445 ms
15,476 KB
testcase_10 AC 621 ms
15,480 KB
testcase_11 AC 2,377 ms
15,468 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def cross?(beam,line)
    va = 2.times.map {|i| line[:a][i] - beam[:a][i]}
    vb = 2.times.map {|i| line[:b][i] - beam[:a][i]}
    vv = 2.times.map {|i| beam[:b][i] - beam[:a][i]}
    rot_a = va[0] * vv[1] - va[1] * vv[0]
    rot_b = vb[0] * vv[1] - vb[1] * vv[0]
    
    (rot_a == 0) || (rot_b == 0) || (rot_a > 0)^(rot_b > 0)
    
end

n = gets.to_i

lines = n.times.map {
    ax,ay,bx,by = gets.split.map(&:to_i)
    {a: [ax,ay], b: [bx,by]}
}

points = lines.each_with_object([]) do |line, points|
    points << line[:a]
    points << line[:b]
end

points.uniq!

puts points.combination(2).map { |a,b|
    lines.select {|line| cross?({a: a, b: b},line)}.count
}.max
0