結果

問題 No.1924 3 color painting on a line
ユーザー lam6er
提出日時 2025-04-16 00:36:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 451 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 70,016 KB
最終ジャッジ日時 2025-04-16 00:41:18
合計ジャッジ時間 3,243 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input().strip()

# Check if all characters are the same
if all(c == s[0] for c in s):
    print(1)
else:
    dp = [0] * (n + 1)
    last = {'R': -1, 'G': -1, 'B': -1}
    for i in range(n):
        c = s[i]
        option1 = dp[i] + 1
        if last[c] == -1:
            option2 = float('inf')
        else:
            option2 = dp[last[c] + 1] + 1
        dp[i + 1] = min(option1, option2)
        last[c] = i
    print(dp[n])
0