結果

問題 No.2924 <===Super Spaceship String===>
ユーザー 👑 loop0919
提出日時 2024-09-16 01:33:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 159,900 KB
最終ジャッジ日時 2024-10-16 17:52:48
合計ジャッジ時間 3,303 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import groupby

S = list(input())
rle_S = []

for s, array in groupby(S):
    if s == "=":
        rle_S.append((s, len(list(array))))
    else:
        rle_S.extend([(s, 1)] * len(list(array)))

stack = []

for s, length in rle_S:
    stack.append((s, length))
    if len(stack) >= 2:
        pre_s, pre_length = stack[-2]
        if pre_s == s == "=":
            stack.pop()
            stack.pop()
            stack.append((s, length + pre_length))
    
    if len(stack) >= 3:
        pre2_s, pre2_length = stack[-3]
        if pre2_s + pre_s + s == "<=>":
            stack.pop()
            stack.pop()
            stack.pop()

print(sum(length for _, length in stack))

0