結果

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

ソースコード

diff #

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

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

# Count the number of color changes when moving from right to left
count = 1
prev = s[-1]
for i in range(n-2, -1, -1):
    if s[i] != prev:
        count += 1
        prev = s[i]

# Count the number of times a color is the same as two positions to the right
d = 0
for i in range(n-3, -1, -1):
    if s[i] == s[i+2]:
        d += 1

print(count - d)
0