結果
問題 |
No.672 最長AB列
|
ユーザー |
|
提出日時 | 2021-03-13 05:17:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 508 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 81,976 KB |
実行使用メモリ | 133,120 KB |
最終ジャッジ日時 | 2024-10-14 17:55:53 |
合計ジャッジ時間 | 2,298 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 6 |
ソースコード
from collections import defaultdict S = input() memo = [0]*(len(S)) n = 0 for i,s in enumerate(S): if s == "A": n += 1 else: n -= 1 memo[i] = n #print(S) #print(memo) first = defaultdict(int) last = defaultdict(int) for i,m in enumerate(memo): if first[m]: last[m] = i+1 else: first[m] = i+1 ans = 0 for k,v in first.items(): if last[k]: ans = max(ans, last[m]-first[m]) if last[0]: ans = max(ans,last[0]) print(ans)