結果

問題 No.672 最長AB列
ユーザー prd_xxxprd_xxx
提出日時 2018-04-14 00:03:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 444 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 17,788 KB
最終ジャッジ日時 2023-09-10 04:16:47
合計ジャッジ時間 4,399 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,000 KB
testcase_01 AC 16 ms
8,020 KB
testcase_02 AC 16 ms
8,024 KB
testcase_03 AC 17 ms
7,992 KB
testcase_04 AC 16 ms
8,000 KB
testcase_05 AC 15 ms
7,956 KB
testcase_06 AC 16 ms
8,032 KB
testcase_07 AC 15 ms
8,036 KB
testcase_08 AC 15 ms
8,012 KB
testcase_09 AC 75 ms
17,788 KB
testcase_10 AC 71 ms
16,084 KB
testcase_11 AC 72 ms
16,156 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