結果
| 問題 |
No.1924 3 color painting on a line
|
| ユーザー |
|
| 提出日時 | 2025-06-25 23:44:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 927 bytes |
| コンパイル時間 | 417 ms |
| コンパイル使用メモリ | 82,768 KB |
| 実行使用メモリ | 80,500 KB |
| 最終ジャッジ日時 | 2025-06-25 23:45:01 |
| 合計ジャッジ時間 | 5,519 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 41 |
ソースコード
MI=lambda:map(int,input().split())
li=lambda:list(MI())
ii=lambda:int(input())
import sys
import bisect
import itertools
n=ii()
s=sys.stdin.readline().strip()
d={'R':0,'G':1,'B':2}
pos=[[] for _ in range(3)]
for i,c in enumerate(s):
pos[d[c]].append(i)
r=[0,0,0]
pre=''
for c in s:
if c!=pre:
r[d[c]]+=1
pre=c
ans=n
for p in itertools.permutations([0,1,2]):
t=[]
cst=0
for x in p:
rc=r[x]
if rc==0:
continue
f=pos[x][0]
l=pos[x][-1]
ok=False
if not t:
ok=True
else:
ok=True
for y in t:
q=pos[y]
idx=bisect.bisect_left(q,f)
if idx<len(q) and q[idx]<=l:
ok=False
break
if ok:
cst+=1
else:
cst+=rc
t.append(x)
if cst<ans:
ans=cst
print(ans)