結果

問題 No.672 最長AB列
ユーザー 👑 H20H20
提出日時 2020-11-05 13:24:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 276 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 107,704 KB
最終ジャッジ日時 2023-09-29 16:53:01
合計ジャッジ時間 2,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,164 KB
testcase_01 AC 72 ms
71,372 KB
testcase_02 AC 71 ms
71,360 KB
testcase_03 AC 72 ms
71,204 KB
testcase_04 AC 71 ms
71,292 KB
testcase_05 AC 73 ms
71,340 KB
testcase_06 AC 70 ms
71,212 KB
testcase_07 AC 72 ms
71,160 KB
testcase_08 AC 72 ms
71,164 KB
testcase_09 AC 110 ms
107,704 KB
testcase_10 AC 94 ms
91,064 KB
testcase_11 AC 99 ms
91,052 KB
testcase_12 AC 88 ms
76,600 KB
testcase_13 AC 84 ms
76,496 KB
testcase_14 AC 86 ms
76,564 KB
testcase_15 AC 87 ms
76,556 KB
testcase_16 AC 86 ms
76,444 KB
testcase_17 AC 97 ms
90,868 KB
testcase_18 AC 81 ms
76,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S=input()
L = len(S)
d = {}
d[0] = -1
cnt = 0
ans = 0
for i in range(L):
    if S[i]=='A':
        cnt += 1
    else:
        cnt -=1
    if cnt not in d:
        # キーが存在しない場合の処理
        d[cnt] = i
    else:
        ans = max(ans,i-d[cnt])
print(ans)
0