結果

問題 No.2076 Concon Substrings (ConVersion)
コンテスト
ユーザー LyricalMaestro
提出日時 2026-06-21 23:20:30
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 765 ms / 5,000 ms
コード長 1,290 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 337 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 89,344 KB
最終ジャッジ日時 2026-06-21 23:20:39
合計ジャッジ時間 8,071 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/2076

       

def main():
    N, A, B = map(int, input().split())
    S = input()

    S = S.replace("con", "_")
    array = []
    prev = False
    for s in S:
        if s == "_":
            if not prev:
                prev = True
                array.append(1)
            else:
                array[-1] += 1
        else:
            prev = False
    
    count = sum(array)
    a_max = (count // A) + (1 if count % A > 0 else 0)

    dp = [-1] * (a_max + 1)
    dp[0] = 0
    for n in array:
        new_dp = [-1] * (a_max +1)

        n_a = 0
        while A * n_a <= n:
            b = n - A * n_a
            b //= B
            for v in range(a_max + 1):
                if dp[v] == -1:
                    break

                if v + n_a > a_max:
                    break

                new_dp[v + n_a] = max(new_dp[v + n_a], dp[v] + b)
            n_a += 1
        dp = new_dp
    answer = 0
    for a in range(a_max + 1):
        max_b = dp[a]
        if max_b == -1:
            continue
        
        v = min(max_b, a)
        if a > v:
            ans = 2 * v + 1

        else:
            ans = 2 * v
        answer = max(answer, ans)
    print(answer)

            




        








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