結果

問題 No.672 最長AB列
ユーザー prd_xxxprd_xxx
提出日時 2018-04-13 23:29:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 492 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 19,044 KB
最終ジャッジ日時 2023-09-10 04:00:39
合計ジャッジ時間 4,389 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,772 KB
testcase_01 AC 16 ms
7,852 KB
testcase_02 AC 17 ms
7,828 KB
testcase_03 AC 16 ms
7,800 KB
testcase_04 AC 17 ms
7,800 KB
testcase_05 AC 17 ms
7,788 KB
testcase_06 AC 17 ms
7,792 KB
testcase_07 AC 16 ms
7,940 KB
testcase_08 AC 17 ms
7,776 KB
testcase_09 AC 70 ms
16,032 KB
testcase_10 AC 76 ms
16,824 KB
testcase_11 WA -
testcase_12 AC 96 ms
13,028 KB
testcase_13 WA -
testcase_14 AC 75 ms
13,512 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 337 ms
19,044 KB
testcase_18 AC 66 ms
10,580 KB
権限があれば一括ダウンロードができます

ソースコード

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

ok = 0
ng = min(a,b)+1
while ng-ok > 1:
    m = (ng+ok) // 2
    if judge(m):
        ok = m
    else:
        ng = m
print(ok*2)
0