結果

問題 No.245 貫け!
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-02-04 11:42:43
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 672 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 11,836 KB
実行使用メモリ 20,864 KB
最終ジャッジ日時 2023-10-20 11:28:28
合計ジャッジ時間 11,826 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,088 KB
testcase_01 AC 86 ms
16,044 KB
testcase_02 AC 89 ms
16,044 KB
testcase_03 AC 87 ms
16,044 KB
testcase_04 AC 90 ms
16,044 KB
testcase_05 AC 92 ms
16,044 KB
testcase_06 AC 90 ms
16,044 KB
testcase_07 AC 86 ms
16,044 KB
testcase_08 AC 153 ms
16,232 KB
testcase_09 AC 480 ms
16,244 KB
testcase_10 AC 670 ms
16,240 KB
testcase_11 AC 2,520 ms
16,496 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