結果

問題 No.672 最長AB列
ユーザー fumofumofunifumofumofuni
提出日時 2023-06-21 01:53:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 226 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 10,664 KB
実行使用メモリ 18,980 KB
最終ジャッジ日時 2023-09-10 21:34:04
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,980 KB
testcase_01 AC 16 ms
7,868 KB
testcase_02 AC 16 ms
7,920 KB
testcase_03 AC 16 ms
7,764 KB
testcase_04 AC 16 ms
7,792 KB
testcase_05 AC 16 ms
7,864 KB
testcase_06 AC 16 ms
7,784 KB
testcase_07 AC 17 ms
7,920 KB
testcase_08 AC 17 ms
7,852 KB
testcase_09 AC 103 ms
18,980 KB
testcase_10 AC 127 ms
15,948 KB
testcase_11 AC 129 ms
15,880 KB
testcase_12 AC 154 ms
14,400 KB
testcase_13 AC 165 ms
14,168 KB
testcase_14 AC 152 ms
14,272 KB
testcase_15 AC 155 ms
14,256 KB
testcase_16 AC 155 ms
14,276 KB
testcase_17 AC 136 ms
15,968 KB
testcase_18 AC 164 ms
14,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S=input()
N=len(S)
dp=[-1]*N*3
cum=0
dp[0]=0
ans=0
for i in range(N):
    if S[i]=='A':
        cum+=1
    else :
        cum-=1
    if dp[cum]!=-1:
        ans = max(ans,i+1-dp[cum])
    else :
        dp[cum]=i+1

print(ans)
0