結果

問題 No.672 最長AB列
ユーザー brthyyjpbrthyyjp
提出日時 2020-05-29 03:10:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 275 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 96,640 KB
最終ジャッジ日時 2024-04-21 20:45:25
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,840 KB
testcase_01 AC 39 ms
51,584 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 AC 38 ms
51,956 KB
testcase_04 AC 38 ms
51,840 KB
testcase_05 AC 39 ms
51,840 KB
testcase_06 AC 39 ms
51,840 KB
testcase_07 AC 40 ms
51,840 KB
testcase_08 AC 46 ms
51,712 KB
testcase_09 AC 82 ms
96,640 KB
testcase_10 AC 69 ms
80,000 KB
testcase_11 AC 75 ms
81,536 KB
testcase_12 AC 58 ms
64,384 KB
testcase_13 AC 55 ms
62,976 KB
testcase_14 AC 57 ms
63,744 KB
testcase_15 AC 58 ms
64,000 KB
testcase_16 AC 57 ms
63,616 KB
testcase_17 AC 71 ms
80,512 KB
testcase_18 AC 54 ms
62,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = str(input())
n = len(s)
C = [0]*(n+1)
for i in range(n):
    if s[i] == 'A':
        C[i+1] = C[i]+1
    else:
        C[i+1] = C[i]-1
#print(C)

d = {}
ans = 0
for i, c in enumerate(C):
    if c in d:
        ans = max(ans, i-d[c])
    else:
        d[c] = i
print(ans)
0