結果

問題 No.672 最長AB列
ユーザー NoneNone
提出日時 2021-03-05 20:32:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 226 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 96,204 KB
最終ジャッジ日時 2024-04-16 08:04:21
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,204 KB
testcase_01 AC 40 ms
52,332 KB
testcase_02 AC 39 ms
52,444 KB
testcase_03 AC 41 ms
52,276 KB
testcase_04 AC 37 ms
52,004 KB
testcase_05 AC 38 ms
53,008 KB
testcase_06 AC 38 ms
51,960 KB
testcase_07 AC 37 ms
52,104 KB
testcase_08 AC 39 ms
52,248 KB
testcase_09 AC 80 ms
96,204 KB
testcase_10 AC 66 ms
84,464 KB
testcase_11 AC 74 ms
88,740 KB
testcase_12 AC 65 ms
76,100 KB
testcase_13 AC 66 ms
75,660 KB
testcase_14 AC 66 ms
75,928 KB
testcase_15 AC 67 ms
75,716 KB
testcase_16 AC 65 ms
75,660 KB
testcase_17 AC 76 ms
89,540 KB
testcase_18 AC 53 ms
72,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S=input().rstrip()
N=len(S)

res=0
c=dict()
c[0]=-1
A,B=0,0
for i in range(N):
    s=S[i]
    if s=="A":
        A+=1
    else:
        B+=1
    if A-B in c:
        res=max(i-c[A-B],res)
    else:
        c[A-B]=i

print(res)
0