結果

問題 No.672 最長AB列
ユーザー 👑 rin204rin204
提出日時 2020-08-05 17:23:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 373 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 22,860 KB
最終ジャッジ日時 2023-10-17 08:05:35
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
9,980 KB
testcase_01 AC 31 ms
9,980 KB
testcase_02 AC 28 ms
9,980 KB
testcase_03 AC 29 ms
9,980 KB
testcase_04 AC 29 ms
9,980 KB
testcase_05 AC 29 ms
9,980 KB
testcase_06 AC 29 ms
9,980 KB
testcase_07 AC 30 ms
9,980 KB
testcase_08 AC 28 ms
9,980 KB
testcase_09 AC 460 ms
22,860 KB
testcase_10 AC 461 ms
22,860 KB
testcase_11 AC 454 ms
22,860 KB
testcase_12 AC 464 ms
16,788 KB
testcase_13 AC 471 ms
16,540 KB
testcase_14 AC 462 ms
16,540 KB
testcase_15 AC 460 ms
16,552 KB
testcase_16 AC 455 ms
16,556 KB
testcase_17 AC 466 ms
22,860 KB
testcase_18 AC 459 ms
16,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
l = len(s)
bef = [999999 for _ in range(2 * l + 1)]
aft = [-1 for _ in range(2 * l + 1)]

cnt = 0
bef[l] = 0
for i, ss in enumerate(s, start = 1):
    if ss == "A":
        cnt += 1
    else:
        cnt -= 1
    bef[l + cnt] = min(bef[l + cnt], i)
    aft[l + cnt] = max(aft[l + cnt], i)

ans = 0
for b, a in zip(bef, aft):
    ans = max(a - b, ans)
print(ans)
0