結果

問題 No.635 自然門松列
ユーザー simansiman
提出日時 2023-01-18 21:18:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 97 ms / 650 ms
コード長 5,063 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 15,384 KB
最終ジャッジ日時 2023-09-02 14:46:01
合計ジャッジ時間 4,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,088 KB
testcase_01 AC 85 ms
15,140 KB
testcase_02 AC 88 ms
15,208 KB
testcase_03 AC 84 ms
15,232 KB
testcase_04 AC 83 ms
15,284 KB
testcase_05 AC 96 ms
15,152 KB
testcase_06 AC 97 ms
15,020 KB
testcase_07 AC 95 ms
15,140 KB
testcase_08 AC 85 ms
15,384 KB
testcase_09 AC 85 ms
15,280 KB
testcase_10 AC 88 ms
15,148 KB
testcase_11 AC 88 ms
15,140 KB
testcase_12 AC 94 ms
15,072 KB
testcase_13 AC 90 ms
15,032 KB
testcase_14 AC 90 ms
15,020 KB
testcase_15 AC 85 ms
15,024 KB
testcase_16 AC 84 ms
15,272 KB
testcase_17 AC 89 ms
15,232 KB
testcase_18 AC 89 ms
15,024 KB
testcase_19 AC 88 ms
15,236 KB
testcase_20 AC 90 ms
15,088 KB
testcase_21 AC 93 ms
15,100 KB
testcase_22 AC 92 ms
15,028 KB
testcase_23 AC 89 ms
15,032 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