結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-01 15:07:24
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,064 bytes
コンパイル時間 11,340 ms
コンパイル使用メモリ 240,332 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 21:46:32
合計ジャッジ時間 12,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2, x3, y3 float64
	_, _ = fmt.Scan(&x1, &y1, &x2, &y2, &x3, &y3)

	sa := (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)
	sb := (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3)
	sc := (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1)

	// fmt.Println(sa, sb, sc)

	// 3辺の長さがすべて同じか、すべて違う場合は正方形を作れない
	if (sa == sb && sb == sc && sc == sa) || (sa != sb && sb != sc && sc != sa) {
		fmt.Println(-1)
		return
	}

	// 4つ目の点の位置
	// この時、2辺の長さと残りの辺の長さが一致しないと正方形は作れない
	var x4, y4 float64
	if sa == sb && sa*2 == sc {
		x4, y4 = x3+x1-x2, x3+x1-y2
	} else if sb == sc && sb*2 == sa {
		x4, y4 = x1+x2-x3, y1+y2-y3
	} else if sc == sa && sc*2 == sb {
		x4, y4 = x2+x3-x1, y2+y3-y1
	} else {
		fmt.Println(-1)
		return
	}
	// fmt.Println(x4, y4)

	// 方眼紙にかけるか = 整数かのチェック
	if x4 == float64(int(x4)) && y4 == float64(int(y4)) {
		fmt.Printf("%.0f %.0f", x4, y4)
	} else {
		fmt.Println(-1)
	}
}
0