結果

問題 No.245 貫け!
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2019-12-23 14:18:34
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 672 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 16,552 KB
最終ジャッジ日時 2023-10-17 07:47:00
合計ジャッジ時間 12,251 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,100 KB
testcase_01 AC 85 ms
16,100 KB
testcase_02 AC 86 ms
16,100 KB
testcase_03 AC 86 ms
16,100 KB
testcase_04 AC 88 ms
16,100 KB
testcase_05 AC 90 ms
16,100 KB
testcase_06 AC 89 ms
16,100 KB
testcase_07 AC 87 ms
16,100 KB
testcase_08 AC 153 ms
16,288 KB
testcase_09 AC 491 ms
16,300 KB
testcase_10 AC 680 ms
16,296 KB
testcase_11 AC 2,607 ms
16,552 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