結果

問題 No.672 最長AB列
ユーザー tails1434tails1434
提出日時 2020-01-22 22:10:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 480 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 122,864 KB
最終ジャッジ日時 2023-09-23 02:48:58
合計ジャッジ時間 4,368 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,692 KB
testcase_01 AC 98 ms
71,632 KB
testcase_02 AC 102 ms
71,724 KB
testcase_03 AC 98 ms
71,716 KB
testcase_04 WA -
testcase_05 AC 98 ms
71,660 KB
testcase_06 AC 98 ms
71,628 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 158 ms
122,864 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 149 ms
105,952 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def main():
    S = input()
    cnt = 0
    diff = [(0,0)]
    for i, s in enumerate(S):
        if s == 'A':
            cnt += 1
        else:
            cnt -= 1

        diff.append((cnt,i+1))

    d = defaultdict(int)
    ans = 0

    for cnt, i in diff:
        if d[cnt]:
            ans = max(ans, i - d[cnt])
            d[cnt] = i
        else:
            d[cnt] = i

    print(ans)
    






if __name__ == "__main__":
    main()
0