結果

問題 No.2312 Turtleman and Gaming Console
ユーザー qwewe
提出日時 2025-05-14 13:04:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,923 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 67,592 KB
最終ジャッジ日時 2025-05-14 13:06:35
合計ジャッジ時間 2,909 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def solve():
    """
    Solves the Turtleman and Gaming Console problem.
    Reads input, determines if Turtleman can play Coderraria without buying new consoles,
    and prints the result.
    """

    # Read the single line of input from standard input and remove leading/trailing whitespace
    line = sys.stdin.readline().strip()

    # --- Parse N ---
    n_str = ""
    idx = 0
    # Iterate through the beginning of the string to find the digits representing N
    # Stop when a non-digit character is encountered or the end of the string is reached.
    while idx < len(line) and line[idx].isdigit():
        # Append the digit character to n_str
        n_str += line[idx]
        # Move to the next character
        idx += 1
    
    # Convert the extracted string part (which represents N) to an integer
    n = int(n_str)

    # --- Extract strings A and B ---
    # Calculate the starting index for string A (immediately after the digits for N)
    a_start = idx
    # Calculate the starting index for string B (immediately after string A)
    # String A has length N.
    b_start = idx + n
    
    # Slice the input line to get string A 
    # A represents which consoles support the game ('o' for yes, 'x' for no)
    # A has length N, spanning indices from a_start up to (but not including) b_start.
    a = line[a_start : b_start]
    
    # Slice the input line to get string B
    # B represents which consoles Turtleman owns ('o' for yes, 'x' for no)
    # B also has length N, spanning indices from b_start up to (but not including) b_start + n.
    b = line[b_start : b_start + n]

    # --- Check if Turtleman can play ---
    # Initialize a boolean flag to False. This flag tracks if we find at least one console
    # that supports the game AND is owned by Turtleman.
    can_play = False
    
    # Iterate through each console type, using an index i from 0 to N-1
    for i in range(n):
        # Check if the i-th console meets both conditions:
        # 1. The i-th console supports Coderraria (a[i] == 'o')
        # 2. Turtleman owns the i-th console (b[i] == 'o')
        if a[i] == 'o' and b[i] == 'o':
            # If both conditions are true for this console i, Turtleman can play the game.
            # Set the flag to True.
            can_play = True
            # Since we've found a suitable console, there's no need to check the remaining ones.
            # We can exit the loop early using break.
            break

    # --- Print the result ---
    # After checking all consoles (or breaking early), check the value of the can_play flag.
    if can_play:
        # If can_play is True, it means a suitable console was found.
        print("Lucky Turtleman")
    else:
        # If can_play is still False, it means no console met both conditions.
        print("Unlucky Turtleman")

# Call the solve function to execute the logic when the script is run.
solve()
0