結果

問題 No.672 最長AB列
ユーザー irumo8202irumo8202
提出日時 2022-01-30 17:08:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 210 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 109,564 KB
最終ジャッジ日時 2023-09-02 01:41:31
合計ジャッジ時間 4,212 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,548 KB
testcase_01 AC 70 ms
71,596 KB
testcase_02 AC 69 ms
71,408 KB
testcase_03 AC 72 ms
71,372 KB
testcase_04 AC 70 ms
71,528 KB
testcase_05 AC 70 ms
71,344 KB
testcase_06 AC 70 ms
71,404 KB
testcase_07 AC 72 ms
71,244 KB
testcase_08 AC 70 ms
71,440 KB
testcase_09 AC 112 ms
109,564 KB
testcase_10 AC 99 ms
92,728 KB
testcase_11 AC 102 ms
92,744 KB
testcase_12 AC 89 ms
78,140 KB
testcase_13 AC 87 ms
78,296 KB
testcase_14 AC 89 ms
78,292 KB
testcase_15 AC 88 ms
78,576 KB
testcase_16 AC 87 ms
78,472 KB
testcase_17 AC 100 ms
92,732 KB
testcase_18 AC 85 ms
78,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = [1 if x == "A" else -1 for x in input()]
left = {0: 0}

ans = 0
x = 0
for i, s in enumerate(S, 1):
    x += s
    if x in left:
        ans = max(ans, i - left[x])
    else:
        left[x] = i

print(ans)
0