結果

問題 No.672 最長AB列
ユーザー ntudantuda
提出日時 2024-01-22 21:21:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 314 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,444 KB
最終ジャッジ日時 2024-01-22 21:21:29
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 40 ms
53,460 KB
testcase_09 AC 118 ms
107,444 KB
testcase_10 AC 100 ms
100,788 KB
testcase_11 AC 92 ms
92,916 KB
testcase_12 AC 69 ms
76,992 KB
testcase_13 AC 66 ms
76,608 KB
testcase_14 AC 67 ms
77,136 KB
testcase_15 AC 68 ms
77,136 KB
testcase_16 AC 68 ms
76,992 KB
testcase_17 AC 89 ms
90,868 KB
testcase_18 AC 67 ms
86,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
tmp = 0
from collections import defaultdict
dic = defaultdict(list)
dic[0].append(0)
for i, s in enumerate(S, start=1):
    if s == "A":
        tmp += 1
    else:
        tmp -= 1
    dic[tmp].append(i)
ans = 0
for k,V in dic.items():
    if len(V) >= 2:
        ans = max(ans,V[-1] - V[0])
print(ans)
0