結果

問題 No.672 最長AB列
ユーザー ynyn
提出日時 2019-01-26 15:59:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 623 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 12,804 KB
最終ジャッジ日時 2023-10-14 10:14:46
合計ジャッジ時間 3,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,136 KB
testcase_01 AC 16 ms
7,840 KB
testcase_02 AC 16 ms
8,028 KB
testcase_03 AC 16 ms
8,092 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 16 ms
7,760 KB
testcase_07 AC 15 ms
7,848 KB
testcase_08 WA -
testcase_09 AC 16 ms
8,284 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()

if s.count("A") == 0 or s.count("B") == 0:
    print(0)
    exit()

l = 0
r = 2
len_s = len(s)

while l < len_s and r < len_s:
    if s[l:r].count("A") != s[l:r].count("B"):
        l += 1
        r += 1
        continue

    if l - 1 >= 0 and r + 1 <= len_s:
        if (s[l - 1] + s[r + 1]).count("A") == 1 and \
            (s[l - 1] + s[r + 1]).count("B") == 1:
            l -= 1
            r += 1
            continue

    if r + 2 <= len_s:
        if s[r:r + 2].count("A") == 1 and \
            s[r:r + 2].count("B") == 1:
            r += 2
            continue

    l += 1
    r += 1

print(r - l)
0