結果

問題 No.672 最長AB列
ユーザー けむけむけむけむ
提出日時 2021-09-05 15:12:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 15,052 KB
最終ジャッジ日時 2023-08-23 14:13:19
合計ジャッジ時間 5,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,052 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 AC 16 ms
7,880 KB
testcase_03 AC 16 ms
7,856 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 15 ms
7,884 KB
testcase_07 AC 15 ms
7,812 KB
testcase_08 RE -
testcase_09 AC 125 ms
9,972 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def AB(S):
    oriS = S
    S = list(S)
    N = len(S)
    ans = 0
    i = 0
    while i <= N - 2:
        patS = S[i:i+2]
        if (patS == ['A', 'B']) or (patS == ['B', 'A']):
            S.pop(i)
            S.pop(i)
            N -= 2
        else:
            i += 1
    resS = ''
    for j in range(len(S)):
        resS += S[j]
    resN = len(resS)
    oriN = len(oriS)
    if (oriS[0] == resS[0]) or (oriS[-1] == resS[0]):
        if (oriS[:resN] == resS) or (oriS[oriN-resN:] == resS):
            ans = oriN - resN
    else:
        splS = resS[0] + resS + resS[0]
        splitted_S = oriS.split(splS)
        len1 = len(splitted_S[0])
        len2 = len(splitted_S[1])
        len_max = max([len1, len2])
        ans = len_max + 1
    return ans

def main():
    S = input()
    print(AB(S))

if __name__ == '__main__':
    main()

0