結果
問題 | No.2021 Not A but B |
ユーザー |
|
提出日時 | 2022-07-29 23:20:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 1,537 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 82,032 KB |
実行使用メモリ | 93,420 KB |
最終ジャッジ日時 | 2024-07-19 16:51:38 |
合計ジャッジ時間 | 3,732 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
# import sys# sys.setrecursionlimit(10**7)# input = sys.stdin.readline# import pypyjit# pypyjit.set_param('max_unroll_recursion=-1')def mp():return map(int,input().split())def lmp():return list(map(int,input().split()))def mps(A):return [tuple(map(str, input().split())) for _ in range(A)]def stoi(LIST):return list(map(int,LIST))def itos(LIST):return list(map(str,LIST))def atoi(LIST): return [ord(i)-ord("a") for i in LIST]def Atoi(LIST): return [ord(i)-ord("A") for i in LIST]def bitA(X,A):return X & 1<<A == 1<<Aimport mathimport bisectimport heapqimport timefrom copy import copy as ccfrom copy import deepcopy as dcfrom itertools import accumulate, productfrom collections import Counter, defaultdict, dequedef ceil(U,V):return (U+V-1)//Vdef modf1(N,MOD):return (N-1)%MOD+1inf = int(1e18)+20mod = int(1e9+7)def rle(lst):ans = []cnt = 1ini = lst[0]for i in range(1, len(lst)):if ini == lst[i]:cnt += 1else:ans.append((ini, cnt))cnt = 1ini = lst[i]ans.append((ini, cnt))return ansn = int(input())s = list(input())ans = 0sr = rle(s)sj = "".join(s)if len(sr) == 1 and sr[0][0] == "A":print(sr[0][1]-1)exit()for c,(i,j) in enumerate(sr):if c == 0 and i == "A":if j == 1:ans += 1else:ans += jelif c == len(sr)-1 and i == "A":if j == 1:ans += 1else:ans += jelif i == "A":if j == 1:ans += 1else:ans += j+1if "BB" in sj:ans += 1print(ans)