結果

問題 No.1924 3 color painting on a line
ユーザー gew1fw
提出日時 2025-06-12 20:17:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 332 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 69,752 KB
最終ジャッジ日時 2025-06-12 20:19:04
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 WA * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if n == 0:
    print(0)
    exit()

changes = 0
for i in range(1, n):
    if s[i] != s[i-1]:
        changes += 1

k = 0
i = 2
while i < n:
    if s[i] == s[i-2] and s[i] != s[i-1]:
        k += 1
        i += 2  # Skip next to avoid overlapping
    else:
        i += 1

print(changes + 1 - k)
0