結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2023-02-22 15:28:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 607 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 117,888 KB |
最終ジャッジ日時 | 2024-07-22 17:05:36 |
合計ジャッジ時間 | 2,395 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
# 二重ループはできない, 2*10**5 # 入力例1,AAABBA。+1 for A, -1 for Bとすれば # levels = [0, 1, 2, 3, 2, 1, 2] # 同じ数字で一番離れている区間が答え S = input() levels = [0] for s in S: if s == 'A': levels.append(levels[-1]+1) if s == 'B': levels.append(levels[-1]-1) #print(levels) from collections import defaultdict dic = defaultdict(list) for i in range(len(levels)): dic[levels[i]].append(i) #print(dic) ans = 0 for d in dic: if len(dic[d]) >= 2: calc = dic[d][-1]-dic[d][0] ans = max(ans, calc) print(ans)