結果

問題 No.672 最長AB列
ユーザー hang_hang_clnhang_hang_cln
提出日時 2018-05-07 21:43:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 503 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 15,736 KB
最終ジャッジ日時 2023-09-10 10:57:39
合計ジャッジ時間 4,219 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,008 KB
testcase_01 AC 16 ms
7,920 KB
testcase_02 AC 16 ms
7,824 KB
testcase_03 AC 16 ms
7,856 KB
testcase_04 AC 16 ms
7,956 KB
testcase_05 AC 16 ms
7,864 KB
testcase_06 AC 16 ms
7,792 KB
testcase_07 AC 16 ms
7,892 KB
testcase_08 AC 16 ms
7,852 KB
testcase_09 AC 17 ms
8,332 KB
testcase_10 AC 40 ms
11,432 KB
testcase_11 AC 40 ms
11,412 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
if len(S) < 2 or S.count('A') == 0 or S.count('B') == 0:
    print('0')
else:
    rep = []
    for s in S:
        if s == 'A':
            rep.append(1)
        else:
            rep.append(-1)
    end = False
    for cutLength in range(2,len(S)+1)[::-1]:
        for startIndex in range(0,len(S)-cutLength+1):
            if sum(rep[startIndex:startIndex+cutLength]) == 0:
                print(cutLength)
                end = True
                break
        if end:
            break
0