結果

問題 No.672 最長AB列
ユーザー AT274_AT274_
提出日時 2019-10-29 18:26:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 331 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 10,524 KB
実行使用メモリ 35,900 KB
最終ジャッジ日時 2023-10-12 23:28:03
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,860 KB
testcase_01 AC 16 ms
7,836 KB
testcase_02 AC 15 ms
7,784 KB
testcase_03 AC 16 ms
7,840 KB
testcase_04 AC 15 ms
7,928 KB
testcase_05 AC 15 ms
7,872 KB
testcase_06 AC 15 ms
7,812 KB
testcase_07 AC 15 ms
7,836 KB
testcase_08 AC 15 ms
7,844 KB
testcase_09 AC 153 ms
35,900 KB
testcase_10 AC 180 ms
24,124 KB
testcase_11 AC 175 ms
24,388 KB
testcase_12 AC 192 ms
11,156 KB
testcase_13 AC 200 ms
15,960 KB
testcase_14 AC 189 ms
11,664 KB
testcase_15 AC 194 ms
13,012 KB
testcase_16 AC 198 ms
13,732 KB
testcase_17 AC 181 ms
25,568 KB
testcase_18 AC 195 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
N = len(S)
cnt = [0] * (N + 1)
farthest = {0: 0}

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

    if cnt[i] not in farthest.keys():
        farthest[cnt[i]] = i
    else:
        ans = max(ans, i - farthest[cnt[i]])

print(ans)
0