結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー gew1fw
提出日時 2025-06-12 21:20:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 73,424 KB
最終ジャッジ日時 2025-06-12 21:22:04
合計ジャッジ時間 2,547 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def parse_runs(s):
    runs = []
    n = len(s)
    i = 0
    while i < n:
        if s[i] == 'c' and i + 2 < n and s[i+1] == 'o' and s[i+2] == 'n':
            count = 0
            j = i
            while j + 2 < n and s[j] == 'c' and s[j+1] == 'o' and s[j+2] == 'n':
                count += 1
                j += 3
            runs.append(count)
            i = j
        else:
            i += 1
    return runs

def compute_max_steps(K, A, B):
    if A == 0 or B == 0:
        return 0
    low = 0
    high = 2 * K  # An upper bound for the number of steps
    best = 0
    while low <= high:
        mid = (low + high) // 2
        sum_needed = 0
        t = mid // 2
        if mid % 2 == 0:
            sum_needed = t * (A + B)
        else:
            sum_needed = t * (A + B) + A
        if sum_needed <= K:
            best = mid
            low = mid + 1
        else:
            high = mid - 1
    return best

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    A = int(input[idx])
    idx += 1
    B = int(input[idx])
    idx += 1
    S = input[idx]
    idx += 1
    
    runs = parse_runs(S)
    total = 0
    for K in runs:
        m = compute_max_steps(K, A, B)
        total += m
    print(total)

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