結果
問題 |
No.1624 三角形の反射
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:20:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 2,075 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 54,084 KB |
最終ジャッジ日時 | 2025-05-14 13:22:33 |
合計ジャッジ時間 | 2,321 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import math a_str = input() # Input format e.g., "X.YYY" # Parse the input string a_str to get an exact fraction for a. # a = (integer part of a * 1000 + fractional part of a) / 1000 parts = a_str.split('.') # parts[0] is the integer part string, parts[1] is the fractional part string (3 digits) # Example: "0.124" -> parts[0]="0", parts[1]="124". numerator_val = 0*1000 + 124 = 124. # Example: "12.345" -> parts[0]="12", parts[1]="345". numerator_val = 12*1000 + 345 = 12345. # A simpler way to form the integer is to concatenate parts[0] and parts[1]. # "0.124" -> "0"+"124" = "0124" -> 124. # "12.345" -> "12"+"345" = "12345" -> 12345. numerator_val = int(parts[0] + parts[1]) denominator_val = 1000 # Since a has 3 decimal places # Simplify the fraction a = numerator_val / denominator_val common_divisor = math.gcd(numerator_val, denominator_val) # (X, Y) is the coordinate of the target vertex in the unfolded plane. # X corresponds to the denominator of the simplified fraction (Q_unfolded). # Y corresponds to the numerator of the simplified fraction (P_unfolded). Y = numerator_val // common_divisor # P_unfolded X = denominator_val // common_divisor # Q_unfolded # Determine which vertex is hit (A, B, or C) vertex_char = '' if (X + Y) % 2 == 0: # If X and Y are both even, or both odd vertex_char = 'A' elif X % 2 != 0 and Y % 2 == 0: # If X is odd and Y is even vertex_char = 'B' elif X % 2 == 0 and Y % 2 != 0: # If X is even and Y is odd vertex_char = 'C' # Calculate the number of reflections using the derived formula: # N_reflections = (X-1) + (Y-1) + (X+Y)//2 + abs(X-Y)//2 # (X-1): reflections from vertical lines (images of side AC) # (Y-1): reflections from horizontal lines (images of side AB) # (X+Y)//2: reflections from diagonals x+y=k (k odd) # abs(X-Y)//2: reflections from diagonals x-y=k (k odd) # Since X and Y are always >= 1 (a >= 0.001), X-1 and Y-1 are non-negative. num_reflections = (X - 1) + (Y - 1) + \ (X + Y) // 2 + \ abs(X - Y) // 2 print(f"{vertex_char} {num_reflections}")