結果

問題 No.635 自然門松列
ユーザー simansiman
提出日時 2023-01-18 20:02:15
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 2,516 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-06-11 20:23:11
合計ジャッジ時間 3,212 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,032 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 76 ms
12,032 KB
testcase_03 WA -
testcase_04 AC 81 ms
12,288 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 80 ms
12,032 KB
testcase_09 AC 76 ms
12,032 KB
testcase_10 RE -
testcase_11 AC 76 ms
12,160 KB
testcase_12 AC 76 ms
12,032 KB
testcase_13 AC 76 ms
12,288 KB
testcase_14 AC 82 ms
12,288 KB
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 AC 76 ms
12,032 KB
testcase_19 AC 78 ms
12,288 KB
testcase_20 AC 76 ms
12,288 KB
testcase_21 AC 82 ms
12,288 KB
testcase_22 WA -
testcase_23 AC 76 ms
12,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

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

  range1 = if x1 >= x2 && y1 < y2
             diff = x1 - x2 + 1
             time = Rational(diff, y2 - y1).ceil
             [time, Float::INFINITY]
           elsif x1 < x2
             if y1 > y2
               diff = x2 - x1
               time = Rational(diff, y1 - y2).ceil
               [0, time]
             else
               [0, Float::INFINITY]
             end
           end

  range2 = if x2 <= x3 && y2 > y3
             diff = x3 - x2 + 1
             time = Rational(diff, y2 - y3).ceil
             [time, Float::INFINITY]
           elsif x2 > x3
             if y2 < y3
               diff = y3 - y2
               time = Rational(diff, y3 - y2).ceil
               [0, time]
             else
               [0, Float::INFINITY];
             end
           end

  if range2[0] <= range1[1]
    true
  elsif range1[0] <= range2[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

  range1 = if x1 <= x2 && y1 > y2
             diff = x2 - x1 + 1
             time = Rational(diff, y1 - y1).ceil
             [time, Float::INFINITY]
           elsif x1 > x2
             if y1 < y2
               diff = x1 - x2
               time = Rational(diff, y2 - y1).ceil
               [0, time]
             else
               [0, Float::INFINITY]
             end
           end

  range2 = if x2 >= x3 && y2 < y3
             diff = x2 - x3 + 1
             time = Rational(diff, y3 - y2).ceil
             [time, Float::INFINITY]
           elsif x2 < x3
             if y2 > y3
               diff = x3 - x2
               time = Rational(diff, y2 - y3).ceil
               [0, time]
             else
               [0, Float::INFINITY]
             end
           end

  if range2[0] <= range1[1]
    true
  elsif range1[0] <= range2[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