結果

問題 No.672 最長AB列
ユーザー GrayCoderGrayCoder
提出日時 2018-04-15 14:41:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 53,612 KB
最終ジャッジ日時 2023-09-10 04:29:52
合計ジャッジ時間 2,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,368 KB
testcase_01 AC 19 ms
8,384 KB
testcase_02 AC 19 ms
8,412 KB
testcase_03 AC 18 ms
8,472 KB
testcase_04 AC 18 ms
8,340 KB
testcase_05 AC 18 ms
8,360 KB
testcase_06 AC 18 ms
8,336 KB
testcase_07 AC 18 ms
8,408 KB
testcase_08 AC 19 ms
8,496 KB
testcase_09 AC 169 ms
53,612 KB
testcase_10 AC 176 ms
37,176 KB
testcase_11 AC 175 ms
37,160 KB
testcase_12 AC 78 ms
19,736 KB
testcase_13 AC 86 ms
24,860 KB
testcase_14 AC 76 ms
20,228 KB
testcase_15 AC 81 ms
21,692 KB
testcase_16 AC 82 ms
22,312 KB
testcase_17 AC 182 ms
37,676 KB
testcase_18 AC 69 ms
17,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def main():
    S = input()

    cnt = [0] * (len(S) + 1)
    for i, s in enumerate(S):
        if s == 'A':
            cnt[i+1] = cnt[i] + 1
        else:
            cnt[i+1] = cnt[i] - 1

    num = defaultdict(list)
    for i, v in enumerate(cnt):
        num[v].append(i)

    ans = 0
    for v in num.values():
        if len(v) > 1:
            ans = max(ans, max(v) - min(v))
    print(ans)

main()
0