結果

問題 No.635 自然門松列
ユーザー simansiman
提出日時 2023-01-18 21:18:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 101 ms / 650 ms
コード長 5,063 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-11 21:20:41
合計ジャッジ時間 3,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,288 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 89 ms
12,416 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 89 ms
12,288 KB
testcase_05 AC 100 ms
12,160 KB
testcase_06 AC 100 ms
12,288 KB
testcase_07 AC 101 ms
12,288 KB
testcase_08 AC 91 ms
12,160 KB
testcase_09 AC 91 ms
12,288 KB
testcase_10 AC 91 ms
12,160 KB
testcase_11 AC 92 ms
12,160 KB
testcase_12 AC 95 ms
12,160 KB
testcase_13 AC 95 ms
12,160 KB
testcase_14 AC 95 ms
12,288 KB
testcase_15 AC 90 ms
12,160 KB
testcase_16 AC 89 ms
12,160 KB
testcase_17 AC 94 ms
12,160 KB
testcase_18 AC 94 ms
12,416 KB
testcase_19 AC 91 ms
12,288 KB
testcase_20 AC 91 ms
12,160 KB
testcase_21 AC 93 ms
12,288 KB
testcase_22 AC 93 ms
12,288 KB
testcase_23 AC 93 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
LOOP_CNT = 50

def check1(x1, x2, x3, y1, y2, y3)
  return true if x1 != x2 && x1 != x3 && x2 != x3 && x1 < x2 && x2 > x3
  return true if y1 != y2 && y1 != y3 && y2 != y3 && y1 < y2 && y2 > y3
  return false if x1 >= x2 && y1 >= y2
  return false if x2 <= x3 && y2 <= y3
  return false if x1 == x3 && y1 == y3

  range1 = if x1 >= x2 && y1 < y2
             diff = x1 - x2 + 1
             time = Rational(diff, y2 - y1).ceil
             ng = 0
             ok = time

             LOOP_CNT.times do
               t = (ng + ok) / 2.0

               if x1 + y1 * t < x2 + y2 * t
                 ok = t
               else
                 ng = t
               end
             end

             [ok, Float::INFINITY]
           elsif x1 < x2
             if y1 > y2
               diff = x2 - x1
               time = Rational(diff, y1 - y2).ceil

               ok = 0
               ng = time

               LOOP_CNT.times do
                 t = (ok + ng) / 2.0

                 if x1 + y1 * t < x2 + y2 * t
                   ok = t
                 else
                   ng = t
                 end
               end

               [0, ok]
             else
               [0, Float::INFINITY]
             end
           end

  range2 = if x2 <= x3 && y2 > y3
             diff = x3 - x2 + 1
             time = Rational(diff, y2 - y3).ceil

             ng = 0
             ok = time

             LOOP_CNT.times do
               t = (ok + ng) / 2.0

               if x2 + y2 * t > x3 + y3 * t
                 ok = t
               else
                 ng = t
               end
             end

             [ok, Float::INFINITY]
           elsif x2 > x3
             if y2 < y3
               diff = x2 - x3
               time = Rational(diff, y3 - y2).ceil

               ok = 0
               ng = time

               LOOP_CNT.times do
                 t = (ok + ng) / 2.0

                 if x2 + y2 * t > x3 + y3 * t
                   ok = t
                 else
                   ng = t
                 end
               end

               [0, ok]
             else
               [0, Float::INFINITY];
             end
           end

  if (range1[0]..range1[1]).cover?(range2[0])
    true
  elsif (range1[0]..range1[1]).cover?(range2[1])
    true
  elsif (range2[0]..range2[1]).cover?(range1[0])
    true
  elsif (range2[0]..range2[1]).cover?(range1[1])
    true
  else
    false
  end
end

def check2(x1, x2, x3, y1, y2, y3)
  return true if x1 != x2 && x1 != x3 && x2 != x3 && x1 > x2 && x2 < x3
  return true if y1 != y2 && y1 != y3 && y2 != y3 && y1 > y2 && y2 < y3
  return false if x1 <= x2 && y1 <= y2
  return false if x2 >= x3 && y2 >= y3
  return false if x1 == x3 && y1 == y3

  range1 = if x1 <= x2 && y1 > y2
             diff = x2 - x1 + 1
             time = Rational(diff, y1 - y2).ceil

             ng = 0
             ok = time

             LOOP_CNT.times do
               t = (ok + ng) / 2.0

               if x1 + y1 * t > x2 + y2 * t
                 ok = t
               else
                 ng = t
               end
             end

             [ok, Float::INFINITY]
           elsif x1 > x2
             if y1 < y2
               diff = x1 - x2
               time = Rational(diff, y2 - y1).ceil

               ok = 0
               ng = time

               LOOP_CNT.times do
                 t = (ok + ng) / 2.0

                 if x1 + y1 * t > x2 + y2 * t
                   ok = t
                 else
                   ng = t
                 end
               end

               [0, ok]
             else
               [0, Float::INFINITY]
             end
           end

  range2 = if x2 >= x3 && y2 < y3
             diff = x2 - x3 + 1
             time = Rational(diff, y3 - y2).ceil

             ng = 0
             ok = time

             LOOP_CNT.times do
               t = (ok + ng) / 2.0

               if x2 + y2 * t < x3 + y3 * t
                 ok = t
               else
                 ng = t
               end
             end

             [ok, Float::INFINITY]
           elsif x2 < x3
             if y2 > y3
               diff = x3 - x2
               time = Rational(diff, y2 - y3).ceil

               ng = time
               ok = 0

               LOOP_CNT.times do
                 t = (ok + ng) / 2.0

                 if x2 + y2 * t < x3 + y3 * t
                   ok = t
                 else
                   ng = t
                 end
               end

               [0, ok]
             else
               [0, Float::INFINITY]
             end
           end

  if (range1[0]..range1[1]).cover?(range2[0])
    true
  elsif (range1[0]..range1[1]).cover?(range2[1])
    true
  elsif (range2[0]..range2[1]).cover?(range1[0])
    true
  elsif (range2[0]..range2[1]).cover?(range1[1])
    true
  else
    false
  end
end

N.times do
  x1, x2, x3, y1, y2, y3 = gets.split.map(&:to_i)

  if check1(x1, x2, x3, y1, y2, y3)
    puts "YES"
  elsif check2(x1, x2, x3, y1, y2, y3)
    puts "YES"
  else
    puts "NO"
  end
end
0