結果

問題 No.1624 三角形の反射
ユーザー lam6er
提出日時 2025-04-09 21:01:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,879 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 76,764 KB
最終ジャッジ日時 2025-04-09 21:03:29
合計ジャッジ時間 3,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input_a = sys.stdin.readline().strip()
    a = float(input_a)
    
    current_x = 0.0
    current_y = 0.0
    dx = 1.0
    dy = a
    reflection_count = 0
    eps = 1e-9
    max_iterations = 10**6  # To prevent infinite loop
    
    for _ in range(max_iterations):
        t_ab = None
        t_ac = None
        t_bc = None
        
        # Check intersection with AB (y=0)
        if dy != 0.0:
            t = (-current_y) / dy
            if t > eps:
                x_at = current_x + dx * t
                if -eps <= x_at <= 1.0 + eps:
                    t_ab = t
        
        # Check intersection with AC (x=0)
        if dx != 0.0:
            t = (-current_x) / dx
            if t > eps:
                y_at = current_y + dy * t
                if -eps <= y_at <= 1.0 + eps:
                    t_ac = t
        
        # Check intersection with BC (x + y = 1)
        denominator = dx + dy
        if denominator != 0.0:
            t = (1.0 - current_x - current_y) / denominator
            if t > eps:
                x_at = current_x + dx * t
                y_at = current_y + dy * t
                if (x_at >= -eps) and (y_at >= -eps):
                    if abs((x_at + y_at) - 1.0) < eps:
                        t_bc = t
        
        candidates = []
        if t_ab is not None:
            x_hit = current_x + dx * t_ab
            y_hit = 0.0
            candidates.append((t_ab, 'AB', x_hit, y_hit))
        
        if t_ac is not None:
            x_hit = 0.0
            y_hit = current_y + dy * t_ac
            candidates.append((t_ac, 'AC', x_hit, y_hit))
        
        if t_bc is not None:
            x_hit = current_x + dx * t_bc
            y_hit = current_y + dy * t_bc
            candidates.append((t_bc, 'BC', x_hit, y_hit))
        
        if not candidates:
            print(-1)
            return
        
        # Select the closest intersection
        t_min, edge_type, x_hit, y_hit = min(candidates, key=lambda x: x[0])
        
        # Check if the hit point is a vertex
        vertex = None
        if abs(x_hit - 1.0) < eps and abs(y_hit) < eps:
            vertex = 'B'
        elif abs(y_hit - 1.0) < eps and abs(x_hit) < eps:
            vertex = 'C'
        elif abs(x_hit) < eps and abs(y_hit) < eps:
            vertex = 'A'
        
        if vertex is not None:
            print(f"{vertex} {reflection_count}")
            return
        
        # Update direction vector based on the edge hit
        reflection_count += 1
        if edge_type == 'AB':
            dy = -dy
        elif edge_type == 'AC':
            dx = -dx
        elif edge_type == 'BC':
            dx, dy = -dy, -dx
        
        # Update current position
        current_x, current_y = x_hit, y_hit
    
    # Exceeded max iterations
    print(-1)

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