結果

問題 No.672 最長AB列
ユーザー yomo3yomo3
提出日時 2020-03-20 17:39:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 456 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 40,544 KB
最終ジャッジ日時 2023-08-21 03:48:43
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,060 KB
testcase_01 AC 16 ms
8,060 KB
testcase_02 AC 16 ms
8,140 KB
testcase_03 AC 17 ms
8,072 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 16 ms
8,068 KB
testcase_07 WA -
testcase_08 AC 16 ms
8,044 KB
testcase_09 AC 88 ms
40,544 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 63 ms
12,576 KB
testcase_13 AC 74 ms
17,336 KB
testcase_14 AC 65 ms
13,092 KB
testcase_15 AC 68 ms
14,140 KB
testcase_16 AC 69 ms
15,144 KB
testcase_17 AC 102 ms
35,608 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

def main():
    S = [0] + list(input())
    N = len(S)-1

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

    l, r = {}, {}

    for i in range(N):
        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