結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
![]() |
提出日時 | 2025-03-20 18:47:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 5,000 ms |
コード長 | 2,266 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 54,324 KB |
最終ジャッジ日時 | 2025-03-20 18:48:01 |
合計ジャッジ時間 | 2,076 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
def find_missing_point(): # Read input points x1, y1, x2, y2, x3, y3 = map(int, input().split()) points = [(x1, y1), (x2, y2), (x3, y3)] candidates = set() # Function to check if four points form a square def is_square(p1, p2, p3, p4): points = [p1, p2, p3, p4] dists = [] for i in range(4): for j in range(i + 1, 4): dx = points[i][0] - points[j][0] dy = points[i][1] - points[j][1] dist_sq = dx * dx + dy * dy dists.append(dist_sq) dists.sort() if len(dists) != 6: return False a = dists[0] if a == 0: return False return (dists[0] == a and dists[1] == a and dists[2] == a and dists[3] == a and dists[4] == 2*a and dists[5] == 2*a) # Iterate through all pairs of points for i in range(3): for j in range(3): if i == j: continue p1 = points[i] p2 = points[j] dx = p2[0] - p1[0] dy = p2[1] - p1[1] # Generate the two possible D candidates d1 = (p2[0] - dy, p2[1] + dx) d2 = (p2[0] + dy, p2[1] - dx) for d in [d1, d2]: # Skip if d is one of the original three points if d in points: continue # Check if the four points form a square if is_square(points[0], points[1], points[2], d): candidates.add(d) # Determine the result if len(candidates) == 1: print(f"{candidates.pop()[0]} {candidates.pop()[1]}" if False else " ".join(map(str, candidates.pop()))) else: valid = [] # Check if all candidates are the same point temp = list(candidates) same = True if len(temp) >= 2: for i in range(1, len(temp)): if temp[i] != temp[0]: same = False break if same: valid.append(temp[0]) if same and len(valid) == 1: print(" ".join(map(str, valid[0]))) else: print(-1) find_missing_point()