結果

問題 No.672 最長AB列
ユーザー ntudantuda
提出日時 2024-01-22 21:24:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 240 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 95,520 KB
最終ジャッジ日時 2024-01-22 21:25:02
合計ジャッジ時間 2,585 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,456 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 76 ms
95,520 KB
testcase_10 AC 65 ms
85,120 KB
testcase_11 AC 70 ms
88,728 KB
testcase_12 AC 61 ms
75,832 KB
testcase_13 AC 81 ms
74,028 KB
testcase_14 AC 61 ms
75,704 KB
testcase_15 AC 61 ms
75,716 KB
testcase_16 AC 61 ms
75,704 KB
testcase_17 AC 72 ms
89,672 KB
testcase_18 AC 49 ms
72,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
tmp = 0
dic = {}
dic[0] = 0
ans = 0
for i, s in enumerate(S, start=1):
    if s == "A":
        tmp += 1
    else:
        tmp -= 1
    if tmp in dic:
        ans = max(ans,i - dic[tmp])
    else:
        dic[tmp] = i
print(ans)
0