結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー 👑 rin204rin204
提出日時 2022-09-16 22:05:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 76,836 KB
最終ジャッジ日時 2023-08-23 15:39:23
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,932 KB
testcase_01 WA -
testcase_02 AC 74 ms
71,124 KB
testcase_03 AC 74 ms
71,440 KB
testcase_04 AC 76 ms
71,268 KB
testcase_05 AC 84 ms
76,272 KB
testcase_06 AC 77 ms
75,732 KB
testcase_07 AC 81 ms
76,484 KB
testcase_08 AC 82 ms
76,328 KB
testcase_09 AC 82 ms
76,276 KB
testcase_10 AC 73 ms
71,408 KB
testcase_11 AC 73 ms
71,232 KB
testcase_12 WA -
testcase_13 AC 72 ms
71,320 KB
testcase_14 AC 73 ms
71,404 KB
testcase_15 AC 78 ms
76,044 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 84 ms
76,268 KB
testcase_20 WA -
testcase_21 AC 72 ms
71,444 KB
testcase_22 WA -
testcase_23 AC 81 ms
76,176 KB
testcase_24 AC 82 ms
76,468 KB
testcase_25 WA -
testcase_26 AC 77 ms
76,012 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 84 ms
76,324 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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)

c = 0
d = 0
cnt = {}
for l in lst:
    c += l // a
    l %= a
    d += l // b
    l %= b
    cnt[l] = cnt.get(l, 0) + 1

def ok(x):
    aa = (x + 1) // 2
    bb = x - aa

    ab = aa * a + bb * b
    if ab > tot:
        return False
    
    if c < aa:
        return False
    elif d >= bb:
        return True

    cc = c - aa
    dd = bb - d

    hq = []
    for k, v in cnt.items():
        heappush(hq, (-k, v))
    
    while cc > 0:
        k, v = heappop(hq)
        k *= -1
        if cc > v:
            cc -= v
            k += a
            dd -= k // b * v
            k %= b
            heappush(hq, (-k, v))
        else:
            v = cc
            cc -= v
            k += a
            dd -= k // b * v
            break


    return dd <= 0



l = 0
r = n + 1
while r - l > 1:
    mid = (l + r) // 2
    if ok(mid):
        l = mid
    else:
        r = mid
print(l)
0