結果

問題 No.635 自然門松列
ユーザー maimai
提出日時 2017-04-10 09:06:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 171 ms / 650 ms
コード長 1,487 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 15,672 KB
最終ジャッジ日時 2023-09-05 13:03:18
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,532 KB
testcase_01 AC 89 ms
15,520 KB
testcase_02 AC 81 ms
15,080 KB
testcase_03 AC 104 ms
15,560 KB
testcase_04 AC 95 ms
15,176 KB
testcase_05 AC 139 ms
15,416 KB
testcase_06 AC 146 ms
15,572 KB
testcase_07 AC 143 ms
15,376 KB
testcase_08 AC 94 ms
15,340 KB
testcase_09 AC 90 ms
15,312 KB
testcase_10 AC 104 ms
15,380 KB
testcase_11 AC 98 ms
15,344 KB
testcase_12 AC 171 ms
15,216 KB
testcase_13 AC 171 ms
15,252 KB
testcase_14 AC 169 ms
15,364 KB
testcase_15 AC 85 ms
15,672 KB
testcase_16 AC 85 ms
15,632 KB
testcase_17 AC 133 ms
15,388 KB
testcase_18 AC 135 ms
15,180 KB
testcase_19 AC 130 ms
15,260 KB
testcase_20 AC 133 ms
15,240 KB
testcase_21 AC 137 ms
15,316 KB
testcase_22 AC 132 ms
15,372 KB
testcase_23 AC 136 ms
15,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def scan; gets.split.map{|e|Rational(e)};end

# 🎍
def kadomatu?(a,b,c)
    a!=b&&b!=c&&c!=a&&((a<b&&b>c)||(a>b&&b<c))
end

def solve1(x1,x2,x3,y1,y2,y3)
    STDERR.puts [x1,x2,x3,y1,y2,y3]*" "
    
    
    # 時間0で🎍
    return "YES" if kadomatu?(x1,x2,x3)
    # 十分な時間経過で🎍
    return "YES" if kadomatu?(y1,y2,y3)
    
    # 二分探索する.
    # tL = 0 , tH = +inf(大きな数値)から開始する.
    # 時刻-infのときに竹の長さが昇順だったとすると,時刻+infは降順になっているはずである.
    # どこかで昇順と降順が切り替わっているはずなので,その時刻を探し,🎍になっているかどうか検証する.
    tl = Rational(0)
    th = Rational(1e15)
    
    # 時刻-infでの『昇順/降順』
    greater = (x1-y1*Rational(1e15) < x3-y3*Rational(1e15))
    
    80.times{
        tc = (tl+th)/2
        if kadomatu?(x1+y1*tc, x2+y2*tc, x3+y3*tc)
            STDERR.puts "found #{tc.to_f}"
            return "YES" 
        end
        
        # 時刻-infの『昇順/降順』と時刻tcの『昇順/降順』が等しいなら
        if greater == (x1+y1*tc < x3+y3*tc)
            tl = tc
        else
            th = tc
        end
    }
    STDERR.puts "#{tl.to_f} < t < #{th.to_f}"
    return "NO"
    
end


def solve(x1,x2,x3,y1,y2,y3)
    solve1(x1,x2,x3,y1,y2,y3)
end


n=gets.to_i
n.times{
    x1,x2,x3,y1,y2,y3 = scan
    puts solve(x1,x2,x3,y1,y2,y3)
}
0