結果

問題 No.1292 パタパタ三角形
ユーザー qwewe
提出日時 2025-05-14 13:18:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,653 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 80,384 KB
最終ジャッジ日時 2025-05-14 13:19:04
合計ジャッジ時間 2,398 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def solve():
    # Read the input string S which defines the sequence of reflections.
    S = sys.stdin.readline().strip()
    
    # Use a set to store the unique states (positions and orientations) of the triangle.
    # Each state is represented by a tuple (p, q, orientation).
    # (p, q) are integer coordinates in a system adapted to the triangular tiling.
    # orientation is 0 for an "UP" pointing triangle (like \triangle) and 1 for a "DOWN" pointing triangle (like \nabla).
    visited = set()
    
    # Initialize the current state of the triangle.
    # Start at coordinate (0,0) with UP orientation.
    current_p = 0
    current_q = 0
    current_orient = 0 # 0 for UP, 1 for DOWN
    
    # Add the initial state to the set of visited states.
    visited.add((current_p, current_q, current_orient))
    
    # Process each reflection operation specified by the characters in S.
    for char in S:
        if current_orient == 0: # Current triangle is UP (\triangle)
            # Define sides for UP triangle: 'a' is bottom horizontal, 'b' is right slanted, 'c' is left slanted.
            if char == 'a':
                # Reflect across 'a' (bottom horizontal side).
                # An UP triangle at (p,q) reflects across its bottom side to become a DOWN triangle at (p, q-1).
                current_q -= 1
                current_orient = 1 # New orientation is DOWN
            elif char == 'b':
                # Reflect across 'b' (right slanted side).
                # An UP triangle at (p,q) reflects across its right side to become a DOWN triangle at (p+1, q).
                current_p += 1
                current_orient = 1 # New orientation is DOWN
            else: # char == 'c'
                # Reflect across 'c' (left slanted side).
                # An UP triangle at (p,q) reflects across its left side to become a DOWN triangle at (p-1, q+1).
                current_p -= 1
                current_q += 1
                current_orient = 1 # New orientation is DOWN
        
        else: # Current triangle is DOWN (\nabla) (current_orient == 1)
            # Define sides for DOWN triangle: 'a' is top horizontal, 'b' is left slanted, 'c' is right slanted.
            if char == 'a':
                # Reflect across 'a' (top horizontal side).
                # A DOWN triangle at (p,q) reflects across its top side to become an UP triangle at (p, q+1).
                current_q += 1
                current_orient = 0 # New orientation is UP
            elif char == 'b':
                # Reflect across 'b' (left slanted side).
                # A DOWN triangle at (p,q) reflects across its left side to become an UP triangle at (p-1, q).
                current_p -= 1
                current_orient = 0 # New orientation is UP
            else: # char == 'c'
                # Reflect across 'c' (right slanted side).
                # A DOWN triangle at (p,q) reflects across its right side to become an UP triangle at (p+1, q-1).
                current_p += 1
                current_q -= 1
                current_orient = 0 # New orientation is UP
                
        # Add the new state (position and orientation) to the visited set.
        # The set automatically handles duplicates: if the state has been visited before, the set size does not change.
        visited.add((current_p, current_q, current_orient))
        
    # The total area covered is equal to the number of unique triangle states visited,
    # since each triangle has area 1 and they tile the plane without interior overlap.
    print(len(visited))

# Call the solve function to run the program.
solve()
0