結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー gew1fw
提出日時 2025-06-12 16:25:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,349 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,660 KB
最終ジャッジ日時 2025-06-12 16:26:07
合計ジャッジ時間 3,175 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from collections import defaultdict

    N, A, B = map(int, sys.stdin.readline().split())
    S = sys.stdin.readline().strip()

    # Parse the string into runs of 'con's
    runs = []
    i = 0
    while i <= len(S) - 3:
        if S[i:i+3] == 'con':
            count = 1
            j = i + 3
            while j <= len(S) - 3 and S[j:j+3] == 'con':
                count += 1
                j += 3
            runs.append(count)
            i = j
        else:
            i += 1

    # Build the frequency map
    freq = defaultdict(int)
    for run in runs:
        freq[run] += 1

    operation_count = 0
    step = 1
    while True:
        target = A if step % 2 == 1 else B
        # Find the first run >= target
        found = False
        for k in list(freq.keys()):
            if k >= target:
                # Process this run
                freq[k] -= 1
                if freq[k] == 0:
                    del freq[k]
                operation_count += 1
                # Split into target and (k - target)
                remaining = k - target
                if remaining > 0:
                    freq[remaining] += 1
                found = True
                break
        if not found:
            break
        step += 1

    print(operation_count)

if __name__ == '__main__':
    main()
0