結果

問題 No.291 黒い文字列
ユーザー gew1fw
提出日時 2025-06-12 13:59:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 82,632 KB
実行使用メモリ 61,628 KB
最終ジャッジ日時 2025-06-12 14:00:11
合計ジャッジ時間 2,578 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input().strip()
# dp represents the counts for each stage: K, KU, KUR, KURO, KUROI
dp = [0, 0, 0, 0, 0]

for c in s:
    # Determine possible characters for the current position
    if c == '?':
        candidates = ['K', 'U', 'R', 'O', 'I']
    else:
        candidates = [c]
    
    new_dp = list(dp)
    for char in candidates:
        current = list(dp)
        if char == 'K':
            current[0] += 1
        elif char == 'U':
            if current[0] > current[1]:
                current[1] += 1
        elif char == 'R':
            if current[1] > current[2]:
                current[2] += 1
        elif char == 'O':
            if current[2] > current[3]:
                current[3] += 1
        elif char == 'I':
            if current[3] > current[4]:
                current[4] += 1
        # Update new_dp to keep the maximum values for each stage
        for i in range(5):
            if current[i] > new_dp[i]:
                new_dp[i] = current[i]
    dp = new_dp

print(dp[4])
0