結果

問題 No.672 最長AB列
ユーザー ynyn
提出日時 2019-01-28 01:25:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 441 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 49,068 KB
最終ジャッジ日時 2024-04-08 16:49:41
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,984 KB
testcase_01 AC 30 ms
9,984 KB
testcase_02 AC 29 ms
9,984 KB
testcase_03 AC 32 ms
9,984 KB
testcase_04 WA -
testcase_05 AC 29 ms
9,984 KB
testcase_06 AC 30 ms
9,984 KB
testcase_07 AC 30 ms
9,984 KB
testcase_08 AC 29 ms
9,984 KB
testcase_09 AC 512 ms
49,068 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 322 ms
17,988 KB
testcase_14 WA -
testcase_15 AC 308 ms
14,916 KB
testcase_16 AC 315 ms
15,812 KB
testcase_17 AC 430 ms
36,268 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

s = input()
l = [0] * (len(s) + 1)

for i in range(len(s)):
    if s[i] == 'A':
        l[i + 1] = l[i] + 1
    else:
        l[i + 1] = l[i] - 1

left = defaultdict(lambda: 10**10)
right = defaultdict(lambda: 0)

for i in range(1, len(s) + 1):
    left[l[i]] = min(left[l[i]], i)
    right[l[i]] = max(right[l[i]], i)

ans = 0
for k, v in left.items():
    ans = max(ans, right[k] - left[k])

print(ans)
0