結果

問題 No.672 最長AB列
ユーザー lllllll88938494lllllll88938494
提出日時 2023-04-15 09:47:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 285 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 107,392 KB
最終ジャッジ日時 2024-04-19 05:44:01
合計ジャッジ時間 2,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,120 KB
testcase_01 AC 41 ms
53,376 KB
testcase_02 AC 46 ms
53,376 KB
testcase_03 AC 43 ms
53,632 KB
testcase_04 AC 42 ms
53,504 KB
testcase_05 AC 45 ms
53,248 KB
testcase_06 AC 45 ms
53,248 KB
testcase_07 AC 41 ms
53,376 KB
testcase_08 AC 48 ms
53,504 KB
testcase_09 AC 114 ms
107,392 KB
testcase_10 AC 82 ms
87,808 KB
testcase_11 AC 108 ms
100,864 KB
testcase_12 AC 84 ms
77,824 KB
testcase_13 AC 80 ms
77,440 KB
testcase_14 AC 84 ms
77,568 KB
testcase_15 AC 84 ms
77,824 KB
testcase_16 AC 84 ms
77,824 KB
testcase_17 AC 84 ms
88,576 KB
testcase_18 AC 74 ms
76,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
s = input()
cnt = defaultdict(list)
cnt[0].append(0)

ans = 0
t = 0
for i in range(len(s)):
    if s[i] == 'A':
        t += 1
    else:
        t -= 1
    if len(cnt[t]) > 0:
        ans = max((i+1)-cnt[t][0],ans)
    cnt[t].append(i+1)

print(ans)
0