結果

問題 No.672 最長AB列
ユーザー ynyn
提出日時 2019-01-26 16:12:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 12,740 KB
最終ジャッジ日時 2023-10-14 10:15:23
合計ジャッジ時間 4,051 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,352 KB
testcase_01 AC 17 ms
7,772 KB
testcase_02 AC 16 ms
8,060 KB
testcase_03 AC 16 ms
8,012 KB
testcase_04 AC 16 ms
7,880 KB
testcase_05 AC 15 ms
7,776 KB
testcase_06 AC 16 ms
7,916 KB
testcase_07 AC 15 ms
7,892 KB
testcase_08 WA -
testcase_09 AC 16 ms
8,268 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 < len_s:
        if (s[l - 1] + s[r]).count("A") == 1 and \
            (s[l - 1] + s[r]).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