結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,328 KB
testcase_01 AC 74 ms
71,228 KB
testcase_02 AC 73 ms
71,104 KB
testcase_03 AC 74 ms
71,320 KB
testcase_04 AC 72 ms
71,168 KB
testcase_05 WA -
testcase_06 AC 75 ms
75,536 KB
testcase_07 AC 81 ms
76,220 KB
testcase_08 WA -
testcase_09 AC 79 ms
76,152 KB
testcase_10 AC 72 ms
71,044 KB
testcase_11 AC 71 ms
71,168 KB
testcase_12 WA -
testcase_13 AC 71 ms
71,128 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 72 ms
71,000 KB
testcase_22 WA -
testcase_23 AC 81 ms
76,060 KB
testcase_24 AC 79 ms
76,100 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 76 ms
76,048 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 83 ms
76,236 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