結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー 👑 rin204rin204
提出日時 2022-09-16 22:42:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 78,372 KB
最終ジャッジ日時 2024-12-21 22:01:07
合計ジャッジ時間 4,112 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, a, b = map(int, input().split())
S = input()
S = S.replace("con", "*")
lst = []
row = 0
for s in S:
    if s == "*":
        row += 1
    else:
        if row != 0:
            lst.append(row)
        row = 0
if row != 0:
    lst.append(row)
lst.sort()
tot = sum(lst)

aa = 0
bb = 0
C = []
for l in lst:
    bb += l // b
    C.append((-(l % b), l))

heapify(C)

def f(a, b):
    if a > b:
        return 2 * b + 1
    else:
        return 2 * a

ans = f(aa, bb)

while C:
    _, d = heappop(C)
    if d < a:
        continue
    bb -= d // b
    d -= a
    aa += 1
    bb += d // b
    heappush(C, (-(d % b), d))
    ans = max(ans, f(aa, bb))


aa = 0
bb = 0
C = []
for l in lst:
    aa += l // a
    C.append((-(l % a), l))

heapify(C)

def f(a, b):
    if a > b:
        return 2 * b + 1
    else:
        return 2 * a

ans = max(ans, f(aa, bb))

while C:
    _, d = heappop(C)
    if d < b:
        continue
    aa -= d // a
    d -= b
    bb += 1
    aa += d // a
    heappush(C, (-(d % a), d))
    ans = max(ans, f(aa, bb))






print(ans)
0