結果

問題 No.2278 Time Bomb Game 2
ユーザー gew1fw
提出日時 2025-06-12 13:50:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 83,360 KB
最終ジャッジ日時 2025-06-12 13:51:15
合計ジャッジ時間 8,211 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def compute_min_distances(c, target):
    n = len(c)
    min_dist = [float('inf')] * n
    # Left to right pass
    last = -float('inf')
    for i in range(n):
        if c[i] == target:
            last = i
            min_dist[i] = 0
        else:
            if last != -float('inf'):
                min_dist[i] = i - last
    # Right to left pass
    last = float('inf')
    for i in range(n-1, -1, -1):
        if c[i] == target:
            last = i
            min_dist[i] = 0
        else:
            if last != float('inf'):
                d = last - i
                if d < min_dist[i]:
                    min_dist[i] = d
    return min_dist

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    K = int(input[idx]); idx +=1
    T = int(input[idx]); idx +=1
    c = input[idx]
    idx +=1
    
    min_dist_B = compute_min_distances(c, 'B')
    min_dist_A = compute_min_distances(c, 'A')
    
    starting_char = c[K-1]
    if starting_char == 'A':
        M = min_dist_B[K-1]
        if M <= T:
            print("Alice")
        else:
            print("Bob")
    else:
        M = min_dist_A[K-1]
        if M <= T:
            print("Bob")
        else:
            print("Alice")

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