結果

問題 No.1624 三角形の反射
ユーザー qwewe
提出日時 2025-04-24 12:32:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,898 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 81,936 KB
実行使用メモリ 76,792 KB
最終ジャッジ日時 2025-04-24 12:33:41
合計ジャッジ時間 3,471 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    a = float(sys.stdin.readline().strip())
    epsilon = 1e-8
    max_reflections = 10**6

    current_x = 0.0
    current_y = 0.0
    direction_dx = 1.0
    direction_dy = a
    reflections = 0

    while reflections <= max_reflections:
        # Compute possible edges
        t_ab = float('inf')
        valid_ab = False
        if direction_dy < -epsilon:
            t_ab = (0.0 - current_y) / direction_dy
            x_ab = current_x + direction_dx * t_ab
            if -epsilon <= x_ab <= 1.0 + epsilon:
                valid_ab = True

        t_ac = float('inf')
        valid_ac = False
        if direction_dx < -epsilon:
            t_ac = (0.0 - current_x) / direction_dx
            y_ac = current_y + direction_dy * t_ac
            if -epsilon <= y_ac <= 1.0 + epsilon:
                valid_ac = True

        t_bc = float('inf')
        valid_bc = False
        denominator = direction_dx + direction_dy
        if abs(denominator) > epsilon:
            t_bc = (1.0 - current_x - current_y) / denominator
            if t_bc > epsilon:
                x_bc = current_x + direction_dx * t_bc
                y_bc = current_y + direction_dy * t_bc
                if (-epsilon <= x_bc <= 1.0 + epsilon and
                    -epsilon <= y_bc <= 1.0 + epsilon):
                    valid_bc = True

        # Find the minimal positive t
        min_t = float('inf')
        edge = None
        if valid_ab and t_ab > epsilon:
            if t_ab < min_t:
                min_t = t_ab
                edge = 'AB'
        if valid_ac and t_ac > epsilon:
            if t_ac < min_t:
                min_t = t_ac
                edge = 'AC'
        if valid_bc and t_bc > epsilon:
            if t_bc < min_t:
                min_t = t_bc
                edge = 'BC'

        if min_t == float('inf'):
            print(-1)
            return

        # Update current position
        new_x = current_x + direction_dx * min_t
        new_y = current_y + direction_dy * min_t

        # Check if new position is a vertex
        if (abs(new_x - 0.0) < epsilon and abs(new_y - 0.0) < epsilon):
            print("A", reflections)
            return
        if (abs(new_x - 1.0) < epsilon and abs(new_y - 0.0) < epsilon):
            print("B", reflections)
            return
        if (abs(new_x - 0.0) < epsilon and abs(new_y - 1.0) < epsilon):
            print("C", reflections)
            return

        # Update direction and increment reflections
        current_x = new_x
        current_y = new_y
        reflections += 1

        if edge == 'AB':
            direction_dy *= -1
        elif edge == 'AC':
            direction_dx *= -1
        elif edge == 'BC':
            new_dx = -direction_dy
            new_dy = -direction_dx
            direction_dx, direction_dy = new_dx, new_dy

    print(-1)

if __name__ == "__main__":
    main()
0