結果

問題 No.672 最長AB列
ユーザー pika4632pika4632
提出日時 2018-05-13 12:09:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 307 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 10,688 KB
実行使用メモリ 36,340 KB
最終ジャッジ日時 2023-09-10 18:43:01
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,820 KB
testcase_01 AC 16 ms
7,832 KB
testcase_02 AC 16 ms
7,980 KB
testcase_03 AC 16 ms
7,864 KB
testcase_04 AC 16 ms
7,928 KB
testcase_05 AC 16 ms
7,808 KB
testcase_06 AC 16 ms
7,824 KB
testcase_07 AC 16 ms
7,820 KB
testcase_08 AC 16 ms
7,852 KB
testcase_09 AC 241 ms
36,340 KB
testcase_10 AC 224 ms
24,508 KB
testcase_11 AC 221 ms
24,652 KB
testcase_12 AC 195 ms
11,356 KB
testcase_13 AC 203 ms
16,104 KB
testcase_14 AC 196 ms
11,984 KB
testcase_15 AC 198 ms
13,308 KB
testcase_16 AC 201 ms
14,032 KB
testcase_17 AC 231 ms
25,904 KB
testcase_18 AC 196 ms
9,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
mx = 0
ss = [0 for a in range(len(s) + 1)]
sss={0:0}
for a,b in enumerate(s):
    if b == "A":
        ss[a + 1] = ss[a] + 1
    else:
        ss[a + 1] = ss[a] - 1
    if not ss[a + 1] in sss:
        sss[ss[a + 1]] = a + 1

for a,b in enumerate(ss):
    mx = max(mx,a - sss[b])
    
print(mx)
0