結果

問題 No.635 自然門松列
ユーザー maimai
提出日時 2017-03-31 21:02:15
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,708 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,352 KB
実行使用メモリ 15,764 KB
最終ジャッジ日時 2023-10-11 12:56:18
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,400 KB
testcase_01 AC 79 ms
15,284 KB
testcase_02 AC 81 ms
15,328 KB
testcase_03 AC 82 ms
15,148 KB
testcase_04 AC 81 ms
15,324 KB
testcase_05 AC 136 ms
15,420 KB
testcase_06 AC 144 ms
15,516 KB
testcase_07 AC 141 ms
15,560 KB
testcase_08 AC 95 ms
15,236 KB
testcase_09 AC 92 ms
15,368 KB
testcase_10 WA -
testcase_11 AC 89 ms
15,508 KB
testcase_12 AC 111 ms
15,520 KB
testcase_13 AC 110 ms
15,340 KB
testcase_14 AC 110 ms
15,372 KB
testcase_15 AC 82 ms
15,736 KB
testcase_16 WA -
testcase_17 AC 98 ms
15,356 KB
testcase_18 AC 102 ms
15,308 KB
testcase_19 AC 97 ms
15,456 KB
testcase_20 AC 98 ms
15,564 KB
testcase_21 AC 96 ms
15,348 KB
testcase_22 AC 99 ms
15,408 KB
testcase_23 AC 98 ms
15,504 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 solve2(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)
    
    # 常に長さが等しくなるような2本の竹の組み合わせが存在するならno
    [[x1,y1],[x2,y2],[x3,y3]].combination(2){|a,b|
        return "NO" if a == b
    }
    
    # x1<x2<x3かつy1<y2<y3ならno.不等号を逆にしても同じ
    return "NO" if x1<x2&&x2<x3&&y1<y2&&y2<y3
    return "NO" if x1>x2&&x2>x3&&y1>y2&&y2>y3
    
    
    # 二分探索する.
    # tL = 0 , tH = (大きな数値)から開始する.
    # tLのときに竹の長さが昇順だったとすると,tHは降順になっているはずである.
    # どこかで昇順と降順が切り替わっているはずなので,その時刻を探し,🎍になっているかどうか検証する.
    tl = Rational(0)
    th = 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
        
        # 時刻0の『昇順/降順』と時刻tcの『昇順/降順』が等しいなら
        if (x1 < x3) == (x1+y1*tc < x3+y3*tc)
            tl = tc
        else
            th = tc
        end
    }
    STDERR.puts "#{tl.to_f} < t < #{th.to_f}"
    return "NO"
end

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