結果

問題 No.672 最長AB列
ユーザー yomo3yomo3
提出日時 2020-03-20 17:45:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 40,580 KB
最終ジャッジ日時 2023-08-21 03:51:39
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,128 KB
testcase_01 AC 17 ms
8,200 KB
testcase_02 AC 16 ms
8,120 KB
testcase_03 AC 16 ms
8,004 KB
testcase_04 AC 17 ms
8,068 KB
testcase_05 AC 16 ms
8,024 KB
testcase_06 AC 16 ms
8,092 KB
testcase_07 AC 17 ms
8,036 KB
testcase_08 AC 16 ms
8,084 KB
testcase_09 AC 83 ms
40,580 KB
testcase_10 AC 102 ms
38,632 KB
testcase_11 AC 107 ms
38,424 KB
testcase_12 AC 63 ms
12,660 KB
testcase_13 AC 78 ms
17,328 KB
testcase_14 AC 65 ms
13,136 KB
testcase_15 AC 68 ms
14,452 KB
testcase_16 AC 71 ms
15,252 KB
testcase_17 AC 105 ms
37,788 KB
testcase_18 AC 59 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

def main():
    S = [0] + list(input())

    d = list(accumulate(S, lambda s, c: s + 1 if c == 'A' else s-1))

    l, r = {}, {}

    for i in range(len(d)):
        if d[i] in l:
            r[d[i]] = i
        else:
            l[d[i]] = i

    ans = 0
    for rk, rv in r.items():
        if rk in l:
            span = rv - l[rk]
            if span > ans:
                ans = span
    print(ans)

main()
0