結果

問題 No.672 最長AB列
ユーザー prd_xxxprd_xxx
提出日時 2018-04-14 00:04:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 444 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 263,232 KB
最終ジャッジ日時 2023-09-10 04:16:54
合計ジャッジ時間 5,742 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,712 KB
testcase_01 AC 77 ms
71,552 KB
testcase_02 AC 78 ms
71,624 KB
testcase_03 AC 80 ms
71,160 KB
testcase_04 AC 76 ms
71,540 KB
testcase_05 AC 77 ms
71,508 KB
testcase_06 AC 75 ms
71,392 KB
testcase_07 AC 74 ms
71,168 KB
testcase_08 AC 74 ms
71,308 KB
testcase_09 AC 90 ms
91,688 KB
testcase_10 AC 93 ms
90,404 KB
testcase_11 AC 95 ms
90,424 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
mem = [0]
a = b = 0
for c in S:
    if c == 'A':
        mem.append(mem[-1] + 1)
        a += 1
    else:
        mem.append(mem[-1] - 1)
        b += 1

def judge(n):
    for a,b in zip(mem, mem[n*2:]):
        if a == b:
            return True
    for a,b in zip(mem[1:], mem[n*2+1:]):
        if a == b:
            return True
    return False

for n in range(min(a,b),-1,-1):
    if judge(n):
        print(n*2)
        exit()
0