結果

問題 No.672 最長AB列
ユーザー htkbhtkb
提出日時 2018-04-14 14:18:27
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 55,756 KB
最終ジャッジ日時 2023-09-10 04:25:56
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,828 KB
testcase_01 AC 16 ms
7,872 KB
testcase_02 AC 16 ms
7,924 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 AC 16 ms
7,952 KB
testcase_05 AC 16 ms
7,772 KB
testcase_06 AC 16 ms
7,884 KB
testcase_07 AC 16 ms
7,800 KB
testcase_08 AC 16 ms
7,800 KB
testcase_09 AC 265 ms
55,756 KB
testcase_10 AC 207 ms
38,916 KB
testcase_11 AC 215 ms
38,968 KB
testcase_12 AC 139 ms
11,132 KB
testcase_13 AC 147 ms
15,924 KB
testcase_14 AC 131 ms
11,664 KB
testcase_15 AC 136 ms
12,984 KB
testcase_16 AC 141 ms
13,852 KB
testcase_17 AC 217 ms
35,952 KB
testcase_18 AC 131 ms
9,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
a = [0]*len(s)
a[0] = 1 if s[0] == "A" else -1
table = {0: [0, 0], a[0]: [1, 0]}
for i in range(1, len(s)):
    a[i] = a[i-1] + (-1, 1)[s[i]=="A"]
    if a[i] not in table:
        table[a[i]] = [i+1, 0]
    else:
        table[a[i]][1] = i+1

result = [b-a for a, b in table.values()]
print(max(result))
0