結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー code-devocode-devo
提出日時 2016-02-06 17:00:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-26 22:17:29
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

XY = Struct.new(:x, :y)

def draw_square(xy1, xy2)
  ret = []

  w = xy2.x - xy1.x
  h = xy2.y - xy1.y

  if w != 0 || h != 0 then
    xy3 = XY.new(xy2.x + h, xy2.y - w)
    xy4 = XY.new(xy3.x - w, xy3.y - h)
    ret << [xy3, xy4]

    xy3 = XY.new(xy2.x - h, xy2.y + w)
    xy4 = XY.new(xy3.x - w, xy3.y - h)
    ret << [xy3, xy4]
  end

  return ret
end

xy1, xy2, xy3 = gets.split.map(&:to_i).each_slice(2).map{|x,y| XY.new(x, y)}

#2点を使って、正方形を描くのに必要な他の2点を列挙する。
#列挙された2点の片方が3点目であれば、もう片方の点が答え。

ans = nil
draw_square(xy1, xy2).each do |xy34|
  ans = xy34[1] if xy34[0] == xy3
  ans = xy34[0] if xy34[1] == xy3
end
draw_square(xy1, xy3).each do |xy34|
  ans = xy34[1] if xy34[0] == xy2
  ans = xy34[0] if xy34[1] == xy2
end

puts ans ? "#{ans.x} #{ans.y}" : -1
0