結果

問題 No.3696 Betting Machine
コンテスト
ユーザー passpin
提出日時 2026-08-14 21:10:55
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,063 ms / 1,500 ms
+ 472µs
コード長 2,612 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 60 ms
コンパイル使用メモリ 15,360 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2026-09-09 20:50:28
合計ジャッジ時間 10,173 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
 
 
def main():
    data = list(map(int, sys.stdin.buffer.read().split()))
    it = iter(data)
 
    S = next(it)
    T = next(it)
    N = next(it)
 
    p0, a0, b0 = next(it), next(it), next(it)
    p1, a1, b1 = next(it), next(it), next(it)
    p2, a2, b2 = next(it), next(it), next(it)
 
    # For a wager x, next wealth is
    # w + (-x + floor(A_i * x / B_i)).
    # Precompute the x-dependent part once.
    d0 = [0] * T
    d1 = [0] * T
    d2 = [0] * T
 
    for x in range(1, T):
        d0[x] = -x + a0 * x // b0
        d1[x] = -x + a1 * x // b1
        d2[x] = -x + a2 * x // b2
 
    # prev[w] stores the exact numerator for success probability with the
    # current number of remaining continuation bets.
    #
    # At the start prev = D_0, so every w < T has value 0.
    prev = [0] * T
 
    # Successful states at the current previous layer have value "scale".
    # It starts at 100^0 and becomes 100^(N-1) before the first-wager scan.
    scale = 1
 
    # Build D_1, D_2, ..., D_(N-1).
    for _ in range(1, N):
        cur = [0] * T
 
        # Local aliases reduce repeated global/name lookups in the hot loop.
        pr = prev
        dd0 = d0
        dd1 = d1
        dd2 = d2
        tt = T
        q0 = p0
        q1 = p1
        q2 = p2
        sc = scale
 
        for w in range(1, tt):
            best = 0
 
            for x in range(1, w + 1):
                n0 = w + dd0[x]
                c0 = sc if n0 >= tt else pr[n0]
 
                n1 = w + dd1[x]
                c1 = sc if n1 >= tt else pr[n1]
 
                n2 = w + dd2[x]
                c2 = sc if n2 >= tt else pr[n2]
 
                value = q0 * c0 + q1 * c1 + q2 * c2
 
                if value > best:
                    best = value
 
            cur[w] = best
 
        prev = cur
        scale *= 100
 
    # Scan every legal first wager and keep every exact tie.
    pr = prev
    best = -1
    optimal = []
 
    for x in range(1, S + 1):
        n0 = S + d0[x]
        c0 = scale if n0 >= T else pr[n0]
 
        n1 = S + d1[x]
        c1 = scale if n1 >= T else pr[n1]
 
        n2 = S + d2[x]
        c2 = scale if n2 >= T else pr[n2]
 
        value = p0 * c0 + p1 * c1 + p2 * c2
 
        if value > best:
            best = value
            optimal = [x]
        elif value == best:
            optimal.append(x)
 
    # best / scale = 100 * q exactly, so integer division performs floor.
    out = [
        str(best // scale),
        str(len(optimal)),
        " ".join(map(str, optimal)),
    ]
    sys.stdout.write("\n".join(out))
 
 
if __name__ == "__main__":
    main()
0