結果

問題 No.2021 Not A but B
ユーザー k_o_pasturek_o_pasture
提出日時 2022-07-30 18:12:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 81,956 KB
実行使用メモリ 97,048 KB
最終ジャッジ日時 2024-07-20 14:25:24
合計ジャッジ時間 3,578 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = list(input())
# N = len(S)
if N == 2:
	print(1)
	exit()

T = []
c = 1
for i in range(1,N):
	if S[i] == S[i-1]:
		c += 1
	else:
		T.append([S[i-1],c])
		c = 1
T.append([S[-1],c])
# print(T)

M = len(T)
ans = N - 1
X = 0
for j in range(M):
	if T[j][0] == 'B':
		if T[j][1] >= 2:
			X += T[j][1] - 1
if X > 0:
	ans -= X - 1

for j in range(1,M-1):
	if T[j][0] == 'A':
		if T[j][1] == 1:
			if (T[j-1][0] == 'B') & (T[j+1][0] == 'B'):
				ans -= 1

print(ans)
0