結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,856 KB
testcase_01 AC 16 ms
7,876 KB
testcase_02 AC 16 ms
7,752 KB
testcase_03 AC 16 ms
7,804 KB
testcase_04 AC 16 ms
7,832 KB
testcase_05 AC 16 ms
7,936 KB
testcase_06 AC 16 ms
7,832 KB
testcase_07 AC 16 ms
7,900 KB
testcase_08 AC 16 ms
7,780 KB
testcase_09 AC 81 ms
17,904 KB
testcase_10 AC 96 ms
18,008 KB
testcase_11 WA -
testcase_12 AC 139 ms
17,904 KB
testcase_13 WA -
testcase_14 AC 91 ms
17,896 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 530 ms
17,912 KB
testcase_18 AC 81 ms
17,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
a = S.count('A')
b = len(S) - a

acum = [0]
bcum = [0]
for c in S:
    if c == 'A':
        acum.append(acum[-1] + 1)
        bcum.append(bcum[-1])
    else:
        acum.append(acum[-1])
        bcum.append(bcum[-1] + 1)

def judge(n):
    n *= 2
    for i in range(len(S)+1-n):
        if acum[i+n] - acum[i] == bcum[i+n] - bcum[i]:
            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