結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-13 05:09:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 448 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 132,864 KB |
| 最終ジャッジ日時 | 2024-10-14 17:31:59 |
| 合計ジャッジ時間 | 2,622 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 10 |
ソースコード
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
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])
print(ans)