結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-13 05:18:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 517 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 82,068 KB |
| 実行使用メモリ | 132,736 KB |
| 最終ジャッジ日時 | 2024-10-14 17:56:23 |
| 合計ジャッジ時間 | 2,237 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 3 |
ソースコード
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])
ans = max(ans,last[0])
ans = max(ans, first[0])
print(ans)