結果

問題 No.672 最長AB列
ユーザー aqua_tenhouaqua_tenhou
提出日時 2021-07-13 21:40:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 238 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 121,724 KB
最終ジャッジ日時 2023-09-15 14:04:02
合計ジャッジ時間 3,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,308 KB
testcase_01 AC 71 ms
71,280 KB
testcase_02 AC 72 ms
71,312 KB
testcase_03 AC 71 ms
71,276 KB
testcase_04 AC 71 ms
71,276 KB
testcase_05 AC 72 ms
71,104 KB
testcase_06 AC 73 ms
71,344 KB
testcase_07 AC 72 ms
71,128 KB
testcase_08 AC 73 ms
71,212 KB
testcase_09 AC 126 ms
121,724 KB
testcase_10 AC 121 ms
106,604 KB
testcase_11 AC 123 ms
93,312 KB
testcase_12 AC 107 ms
88,544 KB
testcase_13 AC 106 ms
88,700 KB
testcase_14 AC 105 ms
88,896 KB
testcase_15 AC 104 ms
88,588 KB
testcase_16 AC 103 ms
88,644 KB
testcase_17 AC 114 ms
94,396 KB
testcase_18 AC 103 ms
89,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
d = [0]
for i,x in enumerate(s):
    p = d[-1] + 1 if x == "A" else d[-1] - 1
    d.append(p)

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